Simple Coding Help - No Promise.

ethan hunt

Well-Known Member
Hi,

How to code AFL for Sell ?

Buy = some Condition A;

Sell =
some Condition B
OR
Target hit [ say 20 points I guess using: ApplyStop(stopTypeProfit,stopModePoint,20,1) ]
OR
Stoploss hit [say 10 points, I guess using: ApplyStop(stopTypeLoss,stopModePoint,10,1) ]
OR
if none of the above
Exit at open at Time [say at 15:00]

Thanks,
 
Last edited:

yusi

Well-Known Member
@primitivetrader : Hope this helps. You can select any higher TimeFrame thru Parameters. Thnx.
@bbhanushali : Your code is always well-crafted and a pleasure to read. No intent to hijack here.

@primitivetrader : An alternate approach, but is quick-n-dirty:
C-like:
_SECTION_BEGIN("PlotM30Shape");
isM30Bar = BarIndex() != LastValue(BarIndex())
           && TimeFrameGetPrice("C", 30 * in1Minute, 0, expandPoint);
PlotShapes(IIf(isM30Bar, shapeSmallCircle, shapeNone), colorYellow, 0, High, 12);
PlotShapes(IIf(isM30Bar, shapeSmallCircle, shapeNone), colorYellow, 0, Low, -12);
_SECTION_END();
 
@primitivetrader : Hope this helps. You can select any higher TimeFrame thru Parameters. Thnx.
Code:
_SECTION_BEGIN("Selected TF Bar High Low Markings");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


tf = Param("Select Time frame (min)",30,1,1440,1);
tfrm=in1Minute*tf;

TimeFrameSet(tfrm);
H1 = Ref(H,-1);
L1 = Ref(L,-1);
TimeFrameRestore();

H1 = TimeFrameExpand(H1, tfrm,expandFirst);
L1 = TimeFrameExpand(L1, tfrm,expandFirst);

Plot(H1,"",colororange,styledots|stylenoline|stylenorescale);
Plot(L1,"",colorbrightgreen,styledots|stylenoline|stylenorescale);


_SECTION_END();
View attachment 42930
hi,
is it possible to have only one single dot exactly below the low of 30M bar and above the high of 30M bar instead of horizontal dots plotted in the future.
please help.
 


If this is what you want, the code was posted earlier in response to you.
I am looking for dots above and below the highest high and lowest low of every 30M time frame on 5 min chart. above is showing dots on the closing candle of 30M time frame
 

Romeo1998

Well-Known Member
can somebody please help me...
i am looking for an afl that put circle/dot above the high and below the low of every 30M bar. but on a 5-minute time frame chart.

please help
this will be helpful, good luck
hi,
is it possible to have only one single dot exactly below the low of 30M bar and above the high of 30M bar instead of horizontal dots plotted in the future.
please help.
just made small change to @bbhanushali Sir's code, good luck :)

Code:
tf = Param("Select Time frame (min)",30,1,1440,1);
tfrm=in1Minute*tf;

TimeFrameSet(tfrm);
H1 = H;
L1 = L;
TimeFrameRestore();

H1 = TimeFrameExpand(H1, tfrm,expandFirst);
L1 = TimeFrameExpand(L1, tfrm,expandFirst);

PlotShapes(IIf(H==H1,shapeSmallCircle,shapeNone),4,0,H,12);
PlotShapes(IIf(L==L1,shapeSmallCircle,shapeNone),27,0,l,-12);
 
hi,
is it possible to have only one single dot exactly below the low of 30M bar and above the high of 30M bar instead of horizontal dots plotted in the future.
please help.
@primitivetrader : Hope it helps. Thnx.
Code:
_SECTION_BEGIN("Selected TF Bar High Low Markings");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


tf = Param("Select Time frame (min)",30,1,1440,1);
tfrm=in1Minute*tf;

TimeFrameSet(tfrm);
H1 = Ref(H,-1);
L1 = Ref(L,-1);
TimeFrameRestore();


H1 = TimeFrameExpand(H1, tfrm,expandFirst);
L1 = TimeFrameExpand(L1, tfrm,expandFirst);

LastbarH = H1 != Ref(H1,1);//Edit: if "-1" then the dots on first TF bar; if "1" then dots on last TF bar
LastbarL = L1 != Ref(L1,1);//Edit: if "-1" then the dots on first TF bar; if "1" then dots on last TF bar

//Use these plots for uncluttered chart with less prominent dashed lines
//Plot(iif(LastbarH,Null,H1),"",colordarkyellow,styledashed|stylenorescale); //uncomment this line if you want not so prominent dashed lines, you can also change color of line
//Plot(iif(LastbarL,Null,L1),"",colorgreen,styledashed|stylenorescale);//uncomment this line if you want not so prominent dashed lines, you can also change color of line

//In case the below is confusing then use the above plots
Plot(IIf(LastbarH,H1,Null),"",colororange,styledots|stylenoline|stylenorescale);//this will plot single dot at the end of last 30m bar on your TF chart
Plot(IIf(LastbarL,L1,Null),"",colorbrightgreen,styledots|stylenoline|stylenorescale);//this will plot single dot at the end of last 30m bar on your TF chart


_SECTION_END();
30mJustDots.png
30mDotnLines.png
 
Last edited:

yusi

Well-Known Member
I am looking for dots above and below the highest high and lowest low of every 30M time frame on 5 min chart. above is showing dots on the closing candle of 30M time frame
Oops, I misunderstood. Try the code below. Note that if two or more bars in the M5 chart share the same High/Low as the M30, all of them will get marked.

C-like:
_SECTION_BEGIN("PlotHhLlM30Shape");
M30High = TimeFrameGetPrice("H", 30 * in1Minute, 0, expandFirst);
PlotShapes(IIf(M30High == High, shapeSmallCircle, shapeNone), colorbrightGreen, 0, High, 12);

M30Low = TimeFrameGetPrice("L", 30 * in1Minute, 0, expandFirst);
PlotShapes(IIf(M30Low == Low, shapeSmallCircle, shapeNone), colorOrange, 0, Low, -12);

//For reference
/*
isM30Bar = BarIndex() != LastValue(BarIndex())
           && TimeFrameGetPrice("C", 30 * in1Minute, 0, expandPoint); //does not mark the last bar
PlotShapes(IIf(isM30Bar, shapeSmallSquare, shapeNone), colorYellow, 0, High, 20);
PlotShapes(IIf(isM30Bar, shapeSmallSquare, shapeNone), colorYellow, 0, Low, -20);
*/
_SECTION_END();
 
Last edited:

Similar threads