NexusFi: Find Your Edge


Home Menu

 





strategy with EMA and range - comaprison of codes in MultiCharts /.NET / AmiBroker


Discussion in MultiCharts

Updated
    1. trending_up 2,448 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
 

strategy with EMA and range - comaprison of codes in MultiCharts /.NET / AmiBroker

 
jamesfisher
City Poland
 
Posts: 14 since Sep 2012
Thanks Given: 1
Thanks Received: 3

I'm doing some comparsion between possibilities (long of the code in some platforms) for strategy with rules:
- We open long positions when the current bar closes above the highest close of the preceding 10 bars. Short positions are initiated when the bar closes below the 10-bar lowest close.
- Long positions are closed when the bar crosses below the 50-period Exponential Moving Average (EMA). We exit short positions when the bar closes above this EMA.
- We use two inputs to set the EMA length and the number of bars that the highest and lowest close is calculated on.

I started coding this in EasyLanguage for MultiCharts. I'm newbie with this language (1 day of exp.). My code:

 
Code
Inputs: Price(Close), Ema_Length(50), Length_Lookback(10); 
Variables: emaCurrent(0);
emaCurrent= XAverage(Price, Ema_Length);

condition1 = Price > Highest(Close[1],Length_Lookback);
condition2 = Price < emaCurrent;
condition3 = Price < Lowest(Close[1],Length_Lookback);
condition4 = Price > emaCurrent;
IF  condition1 then
Buy 1 contract this bar at Close;

IF  condition2 then
Sell this bar at Close;

IF  condition3 then
sellshort 1 contract  this bar at Close;

IF  condition4 then
buytocover this bar at Close;

This same strategy is coded for MultiCharts.NET and present on tradingcode.net with length 103 lines in C#.


My working code for AmiBroker (32 lines of the code):
 
Code
SetOption("InitialEquity",100000);
SetPositionSize(1,spsShares); 
SetTradeDelays(0,0,0,0);

PeriodEMA= Param("PeriodEMA", 50,1,60,1);
PeriodLookback= Param("PeriodLookback", 10,1,60,1);

wartosc_EMA = EMA(C,PeriodEMA);
gorna_banda = Ref(HHV(C,PeriodLookback),-1);
dolne_banda = Ref(LLV(C,PeriodLookback),-1);

otworz_LONG = Cross(C,gorna_banda);
otworz_SHORT = Cross(dolne_banda,C);
zamknij_LONG  = Cross(wartosc_EMA,C);
zamknij_SHORT = Cross(C,wartosc_EMA);

Buy = otworz_LONG;
Sell = zamknij_LONG;
Short = otworz_SHORT;
Cover = zamknij_SHORT;

BuyPrice = ShortPrice = SellPrice = CoverPrice = C;

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

I will be greatful for finishing my code for MultiCharts, so I will have full picture of length of the code. Thanks a lot!


 



Last Updated on May 28, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts