NexusFi: Find Your Edge


Home Menu

 





MC: Simple strategy code problem / Easy Language


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one true with 2 posts (0 thanks)
    2. looks_two max-td with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Jeff65 with 1 posts (1 thanks)
    1. trending_up 7,579 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 true 
Germany
 
Experience: Advanced
Platform: Ninjatrader,Tradestation,MultiCharts
Broker: IB Esignal
Trading: TF,ES,GC,CL
Posts: 17 since Nov 2009
Thanks Given: 15
Thanks Received: 6

Hi all

These are my first try, with Easy Language.
My platform is Multicharts.

I fail, at a simple strategy.
I would like to send a stop and two targets for the broker,
if the first target is reached, will be break-even

Please take a look at the code.

many thanks.



 
Code
  
 //test
[IntrabarOrderGeneration=true]
 Inputs:
 Length(10),             //Averange
 contractsize (2),      //number of contracts
 target_0 ( 4 ),         //target_0 value 
 target_1 ( 8 ),         //target_1 value 
 breakeven ( 4 ),      //Breakeven 
 stoploss ( 11 );       //inital stoploss 
 
 variables:
   oneTick ( 0 ),
   RB (0),
   AvgRB ( 0 );
   
   oneTick = MinMove / PriceScale;     // calculate value of 1 tick.
   RB = Close - Open;
   AvgRB = Average(RB, Length);
   condition1 = AvgRB crosses over 0;
   condition2 = AvgRB crosses under 0;
   
   if MarketPosition = 0 then begin 
   if (condition1) then Buy contractsize Contracts next Bar At Close Limit; 
   if (condition2) then SellShort contractsize  Contracts next Bar At Close Limit;
 
   end;
   
   SetStopContract;
   SetStopLoss((stoploss * oneTick) * BigPointValue);                 //Stop set
   Setbreakeven(breakeven);                                                       //breakeven 


    SetExitOnClose;
    if time > 1530 and MarketPosition = 1 then Sell All Contracts This Bar At Close;
    if time > 1530 and MarketPosition = -1 then Buytocover All Contracts This Bar At Close;


   //Long Target
   if MarketPosition = 1 then begin
        Sell 1 Contract next bar At EntryPrice(0) + ((target_0) * oneTick) Limit;
        Sell 1 Contract next Bar At EntryPrice(0) + ((target_0+target_1)  * oneTick) Limit;
    end;
   
    //Short Target    
   if MarketPosition = -1 then begin
        Buytocover 1 Contract next Bar At EntryPrice(0) - ((target_0) * oneTick) Limit;
        Buytocover 1 Contract Next Bar At EntryPrice(0) - ((target_0+target_1) * oneTick) Limit;
    end;


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
No book, only a stair: journaling fills where price move …
Cryptocurrency
Trump Media to sell instant access to market-moving soci …
Traders Hideout
My Rant with AMP Futures
Trading Reviews and Vendors
Datafeed for Atas
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Mes vs MNQ
6 thanks
NexusFi site changelog and issues/problem reporting
5 thanks
BERN ALGOS algo trading journal
3 thanks
TopStep Trader disappointment
2 thanks
Johnnys Journal
2 thanks
  #3 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927


i am shure someone of the MC-guys takes a look at !


max-td
Reply With Quote
  #4 (permalink)
Jeff65
Gurnee, IL
 
Posts: 46 since Apr 2010
Thanks Given: 17
Thanks Received: 97

Please look this over and test it to see if this is what you were trying to do:

 
Code
//test
[IntrabarOrderGeneration=true]
 Inputs:
     Length(10),        //Averange
     numContracts (2),   //number of contracts
     target_0 ( 4 ),    //target_0 value in ticks
     target_1 ( 8 ),    //target_1 value in ticks
     breakeven ( 4 ),   //Breakeven in ticks
     stoploss ( 11 );   //inital stoploss in ticks
 
 variables:
    OneTickValue$(iff(GetExchangeName="FOREX", MinMove/PriceScale*BigPointValue*100000, MinMove/PriceScale*BigPointValue)),
    OneTickValue(iff(GetExchangeName="FOREX", MinMove/PriceScale*100000, MinMove/PriceScale)),
    intrabarpersist AvgRB( 0 );
   
    Once SetStopContract;    // Enable stop loss per ontract 
    SetExitOnClose;          // Close postion at end of session
   
    AvgRB = Average( C-O, Length );
       condition1 = AvgRB crosses over 0;
    condition2 = AvgRB crosses under 0;
   
    if ( MarketPosition = 0 ) then begin
    
        if (condition1) then Buy numContracts Contracts next Bar at Close Limit; 
        if (condition2) then SellShort numContracts  Contracts next Bar At Close Limit;
        
    end
    else begin
   
        SetStopLoss( stoploss * OneTickValue$ ); //Stop loss in dollars
        Setbreakeven( breakeven * OneTickValue$ ); //breakeven 
       
        if time > 1530 and MarketPosition = 1 then Sell All Contracts This Bar At Close;
        if time > 1530 and MarketPosition = -1 then Buytocover All Contracts This Bar At Close;
         
        //Long Target
       
        if ( MarketPosition = 1 ) then begin
        
            if ( CurrentContracts = numContracts ) then begin
                Sell("L1") 1 Contract next bar At EntryPrice + (target_0*OneTickValue) Limit;
                Sell("L2") 1 Contract next Bar At EntryPrice + (target_1*OneTickValue) Limit;
            end
            else Sell ("L2 ") 1 Contract next Bar At EntryPrice + (target_1*OneTickValue) Limit;
             
        end;
       
        //Short Target 
           
        if ( MarketPosition = -1 )  then begin
            if ( CurrentContracts = numContracts ) then begin
                Buytocover("S1") 1 Contract next Bar At EntryPrice - (target_0*OneTickValue) Limit;
                Buytocover("S2") 1 Contract Next Bar At EntryPrice - (target_1*OneTickValue) Limit;
            end
            else Buytocover("S2 ") 1 Contract Next Bar At EntryPrice - (target_1*OneTickValue) Limit;
       end;
       
end;


Reply With Quote
Thanked by:
  #5 (permalink)
 true 
Germany
 
Experience: Advanced
Platform: Ninjatrader,Tradestation,MultiCharts
Broker: IB Esignal
Trading: TF,ES,GC,CL
Posts: 17 since Nov 2009
Thanks Given: 15
Thanks Received: 6

@Jeff65

Many thanks for your help.
I have it tested today.
It works as it should.


thanks all


Started this thread Reply With Quote




Last Updated on December 19, 2010


© 2026 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 - Downloads - Top
no new posts