Coding Help

asnavale

Well-Known Member
#2
In a Alf,

Can i Only buy if the high where the signal occured is breaken in the next bars

and only short if the low where the signal occured is breaken in the next bars
Ideally, Yes. But not necessarily very rigid rule.

-Anant
 

singhboy

Active Member
#4
Dear Anant I guess he is not talking abt buying randomly above the high of any random bar in randomly picked stock. Perhaps he has any trading set up n he want to buy above the high of the bar where buy signal is generated. If this is the case I suggest thread owner to post his full afl only then any1 can help him.
Otherwise this may work for buying abv the high in next bar

Buy= C> ref(HHV,-1);
 

asnavale

Well-Known Member
#5
Dear Anant I guess he is not talking abt buying randomly above the high of any random bar in randomly picked stock. Perhaps he has any trading set up n he want to buy above the high of the bar where buy signal is generated. If this is the case I suggest thread owner to post his full afl only then any1 can help him.
Otherwise this may work for buying abv the high in next bar

Buy= C> ref(HHV,-1);
Hi singhboy,

I agree with you. Therte should be a system generating the signal and the action would be performed only if his condition is fulfilled. Otherwise it would be as good as tossing a coin. The system should be posted first.

-Anant
 
Last edited:
#6
I am using a nick ma swing trading but i am realising that lot of trade will not happen if the high of the buy signal bar needs to be broken to be traded
 
#7
Hi all,

i am posting the afl for which ema crossover i am not able to code when to buy only if high of ema crossover is broken and sell only if low of ema crossover is broken.

_SECTION_BEGIN("EMA Crossover 50 EMA and 200 EMA with Exploration");

//========================= EMA Crossover =========================

Range1 =Optimize("range1",Param ("range1",50,1,150,1),1,150,1);
Range2 =Optimize("range2",Param ("range2",200,1,1050,1),1,1050,1);

Buy=Cross((EMA(Close,range1)),(EMA(Close,range2)));
Sell=Cross((EMA(Close,range2)),(EMA(Close,range1)));


Short = Cross((EMA(Close,range2)),(EMA(Close,range1)));
Cover= Cross((EMA(Close,range1)),(EMA(Close,range2)));

//========================= Exploration ============================

Filter =Buy OR Sell;

SetOption("NoDefaultColumns", True );
AddTextColumn(Name(),"Symbol",1.2, colorDefault, colorDefault, 90);
AddColumn(DateTime(),"Date & Time", formatDateTime, colorDefault,colorDefault,100);
AddColumn(IIf(Buy,66,IIf(Sell,83,32)),"55-89 EMA Crossover", formatChar, colorWhite, bkcolor =IIf(Buy, colorGreen,IIf(Sell,colorRed,colorDefault)));

//========================= Plot Expanded Average ==================

Plot(EMA( Close,range1), "28 EMA", colorRed );
Plot(EMA( Close,range2), "34 EMA", colorGreen );

//========================= Plot Arrows ============================

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );


_SECTION_END();
 

asnavale

Well-Known Member
#8
Hi all,

i am posting the afl for which ema crossover i am not able to code when to buy only if high of ema crossover is broken and sell only if low of ema crossover is broken.

_SECTION_BEGIN("EMA Crossover 50 EMA and 200 EMA with Exploration");

//========================= EMA Crossover =========================

Range1 =Optimize("range1",Param ("range1",50,1,150,1),1,150,1);
Range2 =Optimize("range2",Param ("range2",200,1,1050,1),1,1050,1);

Buy=Cross((EMA(Close,range1)),(EMA(Close,range2)));
Sell=Cross((EMA(Close,range2)),(EMA(Close,range1)));


Short = Cross((EMA(Close,range2)),(EMA(Close,range1)));
Cover= Cross((EMA(Close,range1)),(EMA(Close,range2)));

//========================= Exploration ============================

Filter =Buy OR Sell;

SetOption("NoDefaultColumns", True );
AddTextColumn(Name(),"Symbol",1.2, colorDefault, colorDefault, 90);
AddColumn(DateTime(),"Date & Time", formatDateTime, colorDefault,colorDefault,100);
AddColumn(IIf(Buy,66,IIf(Sell,83,32)),"55-89 EMA Crossover", formatChar, colorWhite, bkcolor =IIf(Buy, colorGreen,IIf(Sell,colorRed,colorDefault)));

//========================= Plot Expanded Average ==================

Plot(EMA( Close,range1), "28 EMA", colorRed );
Plot(EMA( Close,range2), "34 EMA", colorGreen );

//========================= Plot Arrows ============================

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );


_SECTION_END();
Hi,

Delete the RED colored lines in your code above and replace with the following code:

BuyX=Cross((EMA(Close,range1)),(EMA(Close,range2)));
SellX=Cross((EMA(Close,range2)),(EMA(Close,range1)));
Buy = H > Ref(H, -1) AND Ref(BuyX, -1);
Sell = L < Ref(L, -1) AND Ref(SellX, -1);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

-Anant
 

toughard

Well-Known Member
#9
Hi,

Delete the RED colored lines in your code above and replace with the following code:

BuyX=Cross((EMA(Close,range1)),(EMA(Close,range2)));
SellX=Cross((EMA(Close,range2)),(EMA(Close,range1)));
Buy = H > Ref(H, -1) AND Ref(BuyX, -1);
Sell = L < Ref(L, -1) AND Ref(SellX, -1);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

-Anant
dear ananth sir your code above helped me a lot in my needs...

thanks a lot
 

Karanm

Active Member
#10
I need AFL to Scan / Explore Stocks which were below 200 SMA but have closed today above 200 SMA, 50 SMA is above 200 SMA & 20 SMA is above 50 SMA with 14 days RSI is above 50.

Kindly help

Thanks & Regards
 

Similar threads