Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
MC: Simple strategy code problem / Easy Language
Updated December 19, 2010
Top Posters
looks_one
true
with 2 posts (0 thanks)
looks_two
Jeff65
with 1 posts (1 thanks)
looks_3
max-td
with 1 posts (0 thanks)
looks_4
Quick Summary
with 1 posts (0 thanks)
trending_up
6,866 views
thumb_up
1 thanks given
group
2 followers
forum
4 posts
attach_file
0 attachments
MC: Simple strategy code problem / Easy Language
December 16th, 2010, 05:18 AM
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;
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
December 16th, 2010, 05:21 AM
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 !
December 16th, 2010, 08:01 AM
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;
December 19th, 2010, 08:48 AM
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
Last Updated on December 19, 2010