Simple Coding Help - No Promise.

mcxinvest

Well-Known Member
Found and modified this one,try this now.
Code:
SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
GraphXSpace = 5;
Plot(C,"",colorBlack,styleCandle);
x = Ref(H,-1);
Y = Ref(L,-1);
a=x+1;
b=y-1;
aa=EMA(C,20);
bb=EMA(C,50);
Buy = Cover = C>a AND aa>bb;
Sell = Short = C<b AND aa<bb;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
thank u so much for help. problem solved..

Buy1 = Cross(EMA1,EMA2);
Sell1 = Cross(EMA2,EMA1);

Buy2=ValueWhen(Buy1,H);
sell2=ValueWhen(Sell1,L);

Buy=Cross(C,Buy2);
Sell=Cross(Sell2,C);
some trades are proper some are not..in both the above coding.
 

xsis

Active Member
dear coders - i have a simple request for an afl with exploration for buy & sell signals @eod. the logic is simple and explained in attached screenshots! here the respective SELL & BUY signals are generated in screenshot 1 & 2 respectively!



 

XRAY27

Well-Known Member
Thanks Amit ! I tried both the AFLs bu this is what I'm looking for. I tried draw a rough sketch in paint. :) Let me know if it is possible to code in ami.

I think this is what you are searching... if yes,then tell me i will share this

 
Last edited:
posting the unsolved problem again, I want to plot exit signal if price touch or cross Red line or even if price comes in range of Red line by 0.01%

Code:
// touch 
touchExitShort = H > NWf2f;
touchExitLong  = L < NWf2f;

Modify the exit short level to reduce by 0.01% (for e.g. H > NWf2f * 0.9999)
and increase exit long level by 0.01% (can use L < NWf2f * 1.0001)

Or use parameters etc . . .




With the way the markets are trending all this coding etc . . . seems besides the point :D

All systems (swing/positional) should be long with full scale-ins . . .

Hope everyone is enjoying the ride . . .


Happy :)
 
Last edited:
Hi Experts,

Need a little help here. Hope i will get some.

> I buy and short if the high and low of the signal candles are breached.
> sell and cover signals are on candle close.



right now i am handling this functionality by using "AND Ref(H,1)>=H" at the end of buy code.

This is working fine in amibroker as i m doing intraday.

SCENARIO: I have subscribed with symphony to do auto trading. The logic that I have given them is place a buy order(stop limit) on high of on every bullish candle (green in chart) and if the high is taken out in the next candle it will get filled. If the high is not taken out the order will get cancelled. They have implemented this.

I did this to get better fills (it will get better fills if the order is placed before hand).

PROBLEM: Now i want the same thing to be done by amibroker also (coz it is the one sending orders).
> The amibroker should send buy order on bullish candle, if the next bar breaches high then well and good, if it doesnt breach high of the bullish candle then the buy should disappear.

TRY:
I was thinking on the lines of IIf(Ref(H,1)>=H,buy=True,buy=False); but with no success.

I hope i am clear in explaining the problem.
Looking forward to help and suggestions.

Thanks in advance
 
Last edited:

manishchan

Well-Known Member
I think this is what you are searching... if yes,then tell me i will share this

Received PM to share this AFL.... Credit goes to XRAY27 for sharing this AFL.

PHP:
_SECTION_BEGIN("3 TF Candlestick Bar Chart");
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 3 TIMEFRAMES CANDLESTICK CHART
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Version(5.21);
SetChartOptions(2, chartShowDates);
Title = Name();
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PARAMETERS AND SETTINGS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ChartLum        = Param("Chart Background Color Intensity", 0, 0, 1, 0.01);
TFMinShort      = Param("Short Timeframe (Minutes)", 1, 1, 60, 1);
TFMinMedium = Param("Medium Timeframe (Minutes)", 5, 1, 60, 1);
TFMinLong       = Param("Long Timeframe (Minutes)", 15, 1, 60, 1);
OnSTFBars       = ParamToggle("Short TF Bars", "Off, On", 1);
OnMTFBars       = ParamToggle("Medium TF Bars", "Off, On", 1);
OnLTFBars       = ParamToggle("Long TF Bars", "Off, On", 1);
BarLum1         = Param("Short TF Bar Color Intensity", 0, 0, 1, 0.01);
BarLum2         = Param("Medium TF Bar Color Intensity", 0.70, 0, 1, 0.01);
LTFLine         = Param("Long TF Bar Line Thickness", 3, 0, 10, 1);
BarLum3         = Param("Long TF Bar Color Intensity", 0.50, 0, 1, 0.01);

// Bar Colors for the Short Timeframe candlestick bars:
LineColor       = ColorBlend(colorBlack, colorWhite, BarLum1);
UpBarColor      = ColorBlend(colorBrightGreen, colorWhite, BarLum1);
DnBarColor      = ColorBlend(colorRed, colorWhite, BarLum1);

SetChartBkColor(ColorBlend(colorLightBlue, colorWhite, ChartLum));
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FUNCTIONS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function GetVisibleBarCount()
{
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
return Min( Lvb - fvb, BarCount - fvb );
}

function GfxConvertBarToPixelX( bar )
{
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxchartleft = Status("pxchartleft");
pxchartwidth = Status("pxchartwidth");
return pxchartleft + bar  * pxchartwidth / ( Lvb - fvb + 1 );
}

function GfxConvertValueToPixelY( Value )
{
local Miny, Maxy, pxchartbottom, pxchartheight;
Miny = Status("axisminy");
Maxy = Status("axismaxy");
pxchartbottom = Status("pxchartbottom");
pxchartheight = Status("pxchartheight");
return pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) );
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// MAIN PROGRAM:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if(Interval() != TFMinShort * 60)
{
Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "Set the chart time interval to: " + NumToStr(TFMinShort, 1.0, 1) +
                    " Minute(s) or change the Short Timeframe Parameter setting.";
OnSTFBars      = 0;
OnMTFBars      = 0;
OnLTFBars      = 0;
SetChartBkColor(colorRose);
}

if(TFMinShort >= TFMinLong)
{
Title = Title + "\n" + "\n" + "ALERT, ALERT, ALERT!!!" + "\n" + "The Long Timeframe setting must be longer than the Short Timeframe!";
OnSTFBars      = 0;
OnLTFBars      = 0;
OnLTFBars      = 0;
SetChartBkColor(colorRose);
}

if(OnSTFBars)
{
BarColor       = IIf(Close > Open, UpBarColor, DnBarColor);
SetBarFillColor(BarColor);
Plot(Close, "", LineColor, styleCandle);
}
else
Plot(Close, "", colorBlack, styleCandle  | styleNoDraw);

function PlotBars(TFMinLong, BarLum, Style)
{

// Bar Colors For The Medium and Long Timeframe candlestick bars:
TFLineColor     = ColorBlend(colorBlack, colorWhite, BarLum - 0.1);
TFUpBarColor    = ColorBlend(colorBrightGreen, colorWhite, BarLum);
TFDnBarColor    = ColorBlend(colorRed, colorWhite, BarLum);

TFSec = in1Minute * TFMinLong;
TimeFrameSet(TFSec);
TFOpen          = Open;
TFHigh          = High;
TFLow               = Low;
TFClose         = Close;
TFBarIndex          = BarIndex();
TFLastBarIndex  = LastValue(BarIndex());
TimeFrameRestore();

TFOpen          = TimeFrameExpand(TFOpen, TFSec, expandFirst);
TFHigh          = TimeFrameExpand(TFHigh, TFSec, expandFirst);
TFLow               = TimeFrameExpand(TFLow, TFSec, expandFirst);
TFClose         = TimeFrameExpand(TFClose, TFSec, expandFirst);
TFBarIndex          = TimeFrameExpand(TFBarIndex, TFSec, expandLast + 1);
TFLastBarIndex  = TimeFrameExpand(TFLastBarIndex, TFSec, expandLast + 1);

CandleTop           = Max(TFOpen, TFClose);
CandleBottom        = Min(TFOpen, TFClose);
//============================================================================
// GFX LOW-LEVEL GRAPHICS SECTION.
// DRAWING THE LONG TIMEFRAME CANDLESTICK BARS:
//============================================================================
GfxSetOverlayMode(1);
AllVisibleBars     = GetVisibleBarCount();
fvb                = Status("firstvisiblebar");
ChartWidth     = GfxConvertBarToPixelX(AllVisibleBars );
PixBar             = ChartWidth / AllVisibleBars;
Adjust         = Pixbar * 0.35;
TFMinutes      = TFMinLong / TFMinShort;
NewTFBar           = IIf(TFBarIndex != Ref(TFBarIndex, -1), 1, 0);
BarInd         = BarIndex();
TFLastBarIndex = LastValue(TFLastBarIndex);

// DRAW BAR HISTORY AND THE CURRENT BAR:
for(i = 0; i < AllVisibleBars; i++)
{
  x1 = GfxConvertBarToPixelX(i) * NewTFBar[i + fvb] - Adjust;
  if(BarInd[i + fvb] < TFLastBarIndex AND NewTFBar[i + fvb] == 1)
     {
        Counter = 0;
        for(n = i + 1; NewTFBar[n + fvb] == 0 AND n + fvb < BarCount-1; n++)
            Counter++;
        x2 = GfxConvertBarToPixelX(i + Counter) * NewTFBar[i + fvb] + 1 + Adjust;
     }

  if(TFBarIndex[i + fvb] == TFLastBarIndex)
    x2 = GfxConvertBarToPixelX(i + TFMinutes - 1) * NewTFBar[i + fvb] + 1 + Adjust;

   y1 = GfxConvertValueToPixelY(CandleTop[i + fvb]);
   y2 = GfxConvertValueToPixelY(CandleBottom[i + fvb]);
   yH = GfxConvertValueToPixelY(TFHigh[i + fvb]);
   yL = GfxConvertValueToPixelY(TFLow[i + fvb]);

   // Candle Body:
   FillColor = IIf(TFOpen[i + fvb] < TFClose[i + fvb], TFUpBarColor, TFDnBarColor);
    if(Style == "Fill")
        { 
         GfxSelectPen(TFLineColor, 1);
         GfxSelectSolidBrush(FillColor);
        }
    else
        {
         GfxSelectPen(FillColor, LTFLine);
         GfxSelectSolidBrush(ColorBlend(colorLightBlue, colorWhite, ChartLum));
        }
         
    if(y1 == y2){y1 = y1 - Adjust; y2 = y2 + Adjust;GfxSelectSolidBrush(TFLineColor);}
   if(x1 > 0){
   GfxRectangle( x1, y1, x2, y2);

   // Candle High and Low:
   GfxSelectPen(TFLineColor, 2);
   GfxMoveTo(x2+(x1-x2)/2, y1);
   GfxLineTo(x2+(x1-x2)/2, yH);
   GfxMoveTo(x2+(x1-x2)/2, y2);
   GfxLineTo(x2+(x1-x2)/2, yL);
   RequestTimedRefresh(0);
    }
}
}

if(OnLTFBars)
    PlotBars(TFMinLong, BarLum3, "Line");
if(OnMTFBars)
    PlotBars(TFMinMedium, BarLum2, "Fill");
_SECTION_END();

_SECTION_BEGIN("TITLE");
_N(Title = StrFormat(EncodeColor( colorBlue) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates);

_SECTION_END();
 

amitrandive

Well-Known Member
dear coders - i have a simple request for an afl with exploration for buy & sell signals @eod. the logic is simple and explained in attached screenshots! here the respective SELL & BUY signals are generated in screenshot 1 & 2 respectively!



Looks like a Harami pattern ,check if this helps.Use Scan ,do not explore

Code:
tf = Param( "TF", 70, 1, 100000, 1 ) ;
tfs = tf * in1Minute ;
TimeFrameSet( tfs ) ;
 
GraphXSpace=5;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close",  colorBlack , styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
O1=Ref(O,-1);H1=Ref(H,-1);L1=Ref(L,-1);C1=Ref(C,-1);
O2=Ref(O,-2);H2=Ref(H,-2);L2=Ref(L,-2);C2=Ref(C,-2);
O3=Ref(O,-3);H3=Ref(H,-3);L3=Ref(L,-3);C3=Ref(C,-3);
BT=H2<H3 AND L2<L3 AND H1<H2 AND L1<L2;
ST=H2>H3 AND L2>L3 AND H1>H2 AND L1>L2;
 
 
LDB=C1>O1;LDS=C1<O1;
BULLHarami= O>C1 AND O<O1 AND C<O1 AND C>C1; //AND BT AND LDS;
BEARHarami= O<C1 AND O>O1 AND C>O1 AND C<C1; //AND ST AND LDB ;
Buy=BULLHARAMI;
Sell=BEARHARAMI;
//Short=Sell=bear;
//Cover=0;
//Buy=ExRem(Buy,Sell);Sell=ExRem(Sell,Buy);
//Short=ExRem(Short,Cover);Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,Offset=-10);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,Offset=-10);
//PlotShapes(IIf(Short, shapeHollowDownArrow , shapeNone), colorRed);
//PlotShapes(IIf(Cover, shapeHollowUpArrow , shapeNone), colorGreen);
 
TimeFrameRestore();
 

Similar threads