Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Automate strategy

Hi everyone,

after lot of hardwork, I manage to build a successful strategy, I trade this strategy manually, Now I want to automate this strategy, How I can do it. I am novice programmer, please help me. its very simple strategy buy low sell high.

u can contact me via my email [email protected]

thanks

6 responses

The first thing you should do is learn some basic Python. Once you are slightly familiar with that, you should be able to understand some of the examples here.

My recommendation:
First, go through part or all of the Codecademy Python course which you can find here.

Next, look through the Quantopian discussion board or the Quantopian documentation and find some example algorithms. Try going through the examples and see if you can understand them. From there, you can clone them or copy parts of them to derive your own algorithm from. There are a bunch of good examples here. If you have any questions about Python or Quantopian you can ask and I'll try to help.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Gus

thanks for your recommendation... I will surely try to do that

I have code for my strategy in Amibroker ...I am posting code here....Can you please transfer into Python code so that it will easy for me in to write ..thanks again.

prev=AMA2(C,1,0);  
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),  
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));  
a=Cross(Close,d);  
b=Cross(d,Close);  
state=IIf(BarsSince(a)<BarsSince(b),1,0);  
s=state>Ref(state,-1);  
ss=state<Ref(state,-1);  
sss=state==Ref(state,-1);  
col=IIf(state == 1 ,51,IIf(state ==0,4,1));  
Plot(C,"",Col,64);  
PlotShapes( shapeUpArrow * s ,6,0,L);  
PlotShapes( shapeDownArrow *ss ,4,0,H);

Filter = s OR sss OR sss ;  
AddColumn(C,"close",1.2);  
AddColumn( IIf( s, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (s,colorYellow, colorPink ));  
AddColumn( IIf( Ss, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (Ss,colorPink, colorYellow ));  
AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));

_SECTION_BEGIN("");  
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+_DEFAULT_NAME()+" : {{OHLCX}} {{VALUES}}"  
+"\n"+EncodeColor(colorYellow)+  
WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,","")+  
WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",","")+  
WriteIf( sss ,"No trading signals today.","") );



_SECTION_BEGIN("swing1");  
no=20;  
res=HHV(H,no);  
sup=LLV(L,no);  
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));  
avn=ValueWhen(avd!=0,avd,1);  
supres=IIf(avn==1,sup,res);

a=Cross(C,supres);  
b=Cross(supres,C);

style = a * styleStaircase + b * styleStaircase;

PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));

_SECTION_END();



_SECTION_BEGIN("trend");  
uptrend=PDI(20)>MDI(10)AND Signal(29)<MACD(13);  
downtrend=MDI(10)>PDI(20)AND Signal(29)>MACD(13);


Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",  
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */  
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();

//d = Close > Ref( ChandelierHL(ATR(3),20), -1);
//e =Close < Ref( ChandelierHL(ATR(3),20), -1);
//f = Close < Ref( ChandelierHL(ATR(3),20), -1);
//g = Close > Ref( ChandelierHL(ATR(3),20), -1);

Buy = s AND a AND uptrend ;  
Short = ss AND b AND downtrend ;  
Sell = ss AND b AND downtrend ;  
Cover = s AND a AND uptrend ;

Buy=ExRem(Buy,Sell);  
Sell=ExRem(Sell,Buy);  
Cover=ExRem(Cover,Short);  
Short=ExRem(Short,Cover);

Filter=Buy OR Sell;  
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);  
AddColumn(Sell, "Sell", 1);  
AddColumn(Close,"Close",1.2);  
AddColumn(Volume,"Volume",1.0);

_SECTION_BEGIN("Volume");  
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );  
_SECTION_END();  
// Plot the Buy and Sell arrows.
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;  
PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

Plot(supres,"Swing",colorYellow,styleStaircase);

SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 ))); 


GraphXSpace = 5;  

Hi Praveen - I don't know that Gus (or most others) are willing to translate your code. I worked with AmiBroker and AFL for a few months before scraping that (the API and program in general are very unstable, I would run my script multiple times in a row on the same data and get different results!) Your AFL script appears to be straightforward but it is not immediately translatable into Python. AmiBroker actually runs on block matrices in parallel which create significant problems for certain algorithms. Quantopian performs the backtest in a "linear" fashion thru time, which means it runs slower but actually provides the correct result.

As Gus said, your best bet is to comb thru some of the information on Python and take a crack at this yourself. If I have time this evening I will revisit this page and see if I can help get you started.

Dan is right, it's definitely not trivial to port an algorithm from AmiBroker to Python. Even if someone did it for you, you'd be better off working on it yourself since you would be able to adjust it yourself and learn about Python. If you do what I said, and you're already familiar with programming like you are with AmiBroker, you should be able to port it yourself without too much trouble. If you run into any problems along the way, let me know and I'll try to help.

Hi Gus

thanks but as you have given link for Python learning...its show that course haven't started....Can you please give me link that course already done?

I think the course is available to take for free at any time. It's really more like a game, though. Hover over a lesson and hit "Start course". Does that help?