I did this video tutorial " How to create an advanced MultiCharts EasyLanguage Strategy".
But I tried to change some things with the entries and got stuck.
What I'm trying to make is that each call and the put position will come in turns.
Now you can get call multiple times in a row and the same thing for the put.
I whant it to be
call
put
call
put
would appreciate if you had any tips on solving it!
Thanks in advance!
Code: Select all
inputs:
smalength ( 200 ),
emalength ( 100 ),
hmalength ( 34 ),
target1 ( 12 ),
target2 ( 12 ),
target3 ( 20 ),
stopsize ( 12 ),
BE2 ( 0 ), // 0=false, 1=true
BE3 ( 0 ); // 0=false, 1=true
vars:
TickSize ( MinMove / PriceScale ),
smav ( 0 ),
emav ( 0 ),
hmav ( 0 ),
t1 ( Target1 * TickSize ),
t2 ( (Target1 + Target2) * TickSize ),
t3 ( (Target1 + Target2 + Target3) * TickSize ),
st1 ( 0 ),
st2 ( 0 ),
st3 ( 0 );
smav = Average(Close, smalength);
emav = XAverage(Close, emalength);
hmav = jtHMA(Close, hmalength);
// open new positions
if MarketPosition = 0 then begin
if smav > smav[1] and emav > emav[1] and hmav > hmav[1] then begin
Buy ("Enter long") 3 Contracts Next Bar At Market;
end;
if smav < smav[1] and emav < emav[1] and hmav < hmav[1] then begin
SellShort ("Enter short") 3 Contracts Next Bar At Market;
end;
end;
// manage open orders
if MarketPosition = 1 then begin
st1 = EntryPrice - (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (stopsize * TickSize));
if CurrentContracts = 1 then begin
Sell ("Exit l3-c1 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
Sell ("Exit l2-c2 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c2 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
Sell ("Exit l1-c3 Target") 1 Contracts Next Bar At (EntryPrice + t1) Limit;
Sell ("Exit l1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
Sell ("Exit l2-c3 Target") 1 Contracts Next Bar At (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
Sell ("Exit l3-c3 Target") 1 Contracts Next Bar At (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (stopsize * TickSize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (stopsize * TickSize));
if CurrentContracts = 1 then begin
BuyToCover ("Exit s3-c1 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 2 then begin
BuyToCover ("Exit s2-c2 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c2 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 1 Contracts Next Bar At st3 Stop;
end;
if CurrentContracts = 3 then begin
BuyToCover ("Exit s1-c3 Target") 1 Contracts Next Bar At (EntryPrice - t1) Limit;
BuyToCover ("Exit s1-c3 Stop") 1 Contracts Next Bar At st1 Stop;
BuyToCover ("Exit s2-c3 Target") 1 Contracts Next Bar At (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 1 Contracts Next Bar At st2 Stop;
BuyToCover ("Exit s3-c3 Target") 1 Contracts Next Bar At (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 1 Contracts Next Bar At st3 Stop;
end;
end;