Need to convert my strategy into amibroker script

#1
Hi,

I am not good in programming.
I need help in converting following strategy into Amibroker script.

Any help is appreciated.

*************************
I use 4 different EMAs.
3EMA
5EMA
13EMA
34EMA

Condition 1
-----------
When 13EMA is above 34EMA, initiate a long position.
Now, when 3EMA cuts 5EMA from upside moving towards downside, exit long position.

Condition 2
-----------
When 13EMA is below 34EMA, initiate a short position.
Now, when 3EMA cuts 5EMA from downside moving towards upside, exit short position.
*************************************

Regards
Yogesh
 
#2
dear yogesh,try this

LongPer = Param("Long Period", 13, 30, 100, 5);
ShortPer = Param("Short Period", 34, 30, 100, 5);
LongPer1 = Param("Long Period1", 3, 30, 100, 5);
ShortPer1 = Param("Short Period1", 5, 30, 100, 5);

LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LongMA1 = EMA(C, LongPer1);
ShortMA1 = EMA(C, ShortPer1);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorRed, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorBrightGreen, styleLine);
Plot(LongMA1, " EMA(C, " + WriteVal(LongPer1, 1) + ")", colorBlue, styleLine);
Plot(ShortMA1, " EMA(C, " + WriteVal(ShortPer1, 1) + ")", colorBrown, styleLine);

Buy = Cross(ShortMA, LongMA);
Sell = Cross(LongMA, ShortMA);
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
AddColumn(Buy,"Buy");
AddColumn(Sell,"sell");
AddColumn(BuyPrice,"BuyPrice");
AddColumn(SellPrice,"SellPrice");
 
#3
Hi Bhulokeshwar,

Thanks for creating this script for me.

There are few changes that we need to do..I 'd really appreciate, if you can pls do that for me.

1.Arrows are opposite.i.e. wherever sell arrow is indicated, it should be buy arrow and wherever buy arrow is indicated, it should be sell arrow.
2.When a Long is initiated, as per my strategy, the moment 3EMA cuts 5EMA, it should exit Long position.
3.When a Short is initiated, as per my strategy, the moment 3EMA cuts 5EMA, it should exit short position.

Once again, I thank you many for helping me.

Regards
Yogesh

dear yogesh,try this

LongPer = Param("Long Period", 13, 30, 100, 5);
ShortPer = Param("Short Period", 34, 30, 100, 5);
LongPer1 = Param("Long Period1", 3, 30, 100, 5);
ShortPer1 = Param("Short Period1", 5, 30, 100, 5);

LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LongMA1 = EMA(C, LongPer1);
ShortMA1 = EMA(C, ShortPer1);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorRed, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorBrightGreen, styleLine);
Plot(LongMA1, " EMA(C, " + WriteVal(LongPer1, 1) + ")", colorBlue, styleLine);
Plot(ShortMA1, " EMA(C, " + WriteVal(ShortPer1, 1) + ")", colorBrown, styleLine);

Buy = Cross(ShortMA, LongMA);
Sell = Cross(LongMA, ShortMA);
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
AddColumn(Buy,"Buy");
AddColumn(Sell,"sell");
AddColumn(BuyPrice,"BuyPrice");
AddColumn(SellPrice,"SellPrice");
 
#4
hi
same thing i observed after posting.Now i am correcting it

LongPer = Param("Long Period", 13, 30, 100, 5);
ShortPer = Param("Short Period", 34, 30, 100, 5);
LongPer1 = Param("Long Period1", 3, 30, 100, 5);
ShortPer1 = Param("Short Period1", 5, 30, 100, 5);

LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LongMA1 = EMA(C, LongPer1);
ShortMA1 = EMA(C, ShortPer1);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Plot(LongMA1, " EMA(C, " + WriteVal(LongPer1, 1) + ")", colorBlue, styleLine);
Plot(ShortMA1, " EMA(C, " + WriteVal(ShortPer1, 1) + ")", colorBrown, styleLine);

Buy = Cross(LongMA, ShortMA);
Sell = Cross(ShortMA, LongMA);
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
AddColumn(Buy,"Buy");
AddColumn(Sell,"sell");
AddColumn(BuyPrice,"BuyPrice");
AddColumn(SellPrice,"SellPrice");
 
#5
Dear yogesh
correction done for sl.no-1
but 2 and 3 rd iam not done because both are 3 and 5 ema are very close
so many time both will intersect in actual trading.even u want for exit ,i will do it either before 22/12 or later 28/12
 
#6
Thanks Bhulokeshwar,

The reason I use 3EMA and 5EMA is becoz they give me target for the trade.

You are right, they intersect a lot in actual trading. However, in my manual testing that I tried(without your code, only tried it with excel and watching graph), it seems that most of the time when you are in trade and when 3EMA & 5EMA give exit signal, it rarely bounces back and continues the trade.

However, there are incidents when it bounces back like for eg. if you check the daily graph of nifty. This strategy suggests a sell on 12/9/08 and then on 19/9/08 it suggest to exit as the 3EMA and 5EMA cut each other.

Now, after such incident, a better idea would to book 50%profit when 3EMA and 5EMA intersect and then wait for 3EMA to further cut 13EMA and book remaining 50% and exit the trade completely.

Following the example quoted above, if you see, this strategy caught the oct downfall on 12/9/08 and when oct came it gave brilliant profit.

I am not sure, how many ppl here would agree with me on this strategy.
Nevertheless, I am thankful one soul at least for believing in me.

I wait for you..take your time.

Thanks again
Yogesh
 
#7
dear yogesh,good luck,i am giving complete afl as u required.do u want audible alarm also?
////////////////////////////////////////////
_SECTION_BEGIN("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 13, 30, 100, 5);
ShortPer = Param("Short Period", 34, 30, 100, 5);
LongPer1 = Param("Long Period1", 3, 30, 100, 5);
ShortPer1 = Param("Short Period1", 5, 30, 100, 5);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LongMA1 = EMA(C, LongPer1);
ShortMA1 = EMA(C, ShortPer1);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Plot(LongMA1, " EMA(C, " + WriteVal(LongPer1, 1) + ")", colorBlue, styleLine);
Plot(ShortMA1, " EMA(C, " + WriteVal(ShortPer1, 1) + ")", colorBrown, styleLine);
Buy = Cross(LongMA, ShortMA);
Short = Cross(ShortMA, LongMA);
Cover = Cross(LongMA1, ShortMA1);
Sell = Cross(ShortMA1, LongMA1);
PlotShapes(shapeUpArrow * Buy, colorBrightGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Short, colorRed, 0, H, - 10);
PlotShapes(shapeUpArrow * Cover, colorBlue, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorBrown, 0, H, - 10);
Filter=Buy OR Sell;
Filter=Short OR Cover;
Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover); Cover=ExRem(Cover,Short);
AddColumn(Buy,"Buy");
AddColumn(Sell,"sell");
AddColumn(Short,"short");
AddColumn(Cover,"cover");
AddColumn(BuyPrice,"BuyPrice");
AddColumn(SellPrice,"SellPrice");
AddColumn(ShortPrice,"shortPrice");
AddColumn(CoverPrice,"coverPrice");
_SECTION_END();
 
#8
Hi,

Fantastic!!

Work Well Done!! Kudoos to you friend.

It now works exactly,the way I wanted it to.

-----------------------------------------------

Thank you very much.

God Bless

Take care

Regards
Yogesh
 
#9
dear yogish
can you add volume in this afl to give a good entry point on an intraday?
like V> 1.5 X 20 MA of Vol then only buy


with regards
ravi
 
#10
Sir i need and afl that plots DYNAMIC support and resistance lines on intraday charts along with entry and exit signals...i also need an indicator that plots red colour for selling pressure and green colour for buying pressure on intrday charts...
 

Similar threads