Need some guidance  [SOLVED]

Questions about MultiCharts and user contributed studies.
bombaybom
Posts: 12
Joined: 13 Nov 2014
Has thanked: 7 times

Need some guidance

Postby bombaybom » 06 Aug 2015

Hi

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;

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Need some guidance

Postby TJ » 07 Aug 2015

Hi

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!
::
First, you need to keep track of your trade direction. (call or put)

To do that, you can find out your position using the keyword MarketPosition,
then store the value in a variable for later reference.

When the MarketPosition = 0 (ie you are ready to trade),
then look up the variable to see which direction you went last time.
If the value is 1, then you should go short this time. And vice versa.


To code this routine is not difficult,
it does take time though.

Before you start, you do need to write out your logic in step-by-step instructions,
similar to what I have written above, but in more detail.


This is a broad general view, hope it can get you started.

bombaybom
Posts: 12
Joined: 13 Nov 2014
Has thanked: 7 times

Re: Need some guidance

Postby bombaybom » 08 Aug 2015

Hi

I have tried this part, but somthing is not working for me.

I am thinking wrong?

Code: Select all

vars: PuttCall (0);

if MarketPosition = 0 then Begin


If Close > sme and putcall < 1 then
Begin
buy ("Enter Long") 1 contracts Next bar at market;
PutCall = 1;
End;

If Close > sme and putcall > -1 then
Begin
SellShort ("Enter Short") 1 contracts Next bar at market;
PutCall = -1;
End;

End;

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Need some guidance

Postby TJ » 08 Aug 2015

Hi

I have tried this part, but somthing is not working for me.

I am thinking wrong?

Code: Select all

vars: PuttCall (0);

if MarketPosition = 0 then Begin


If Close > sme and putcall < 1 then
Begin
buy ("Enter Long") 1 contracts Next bar at market;
PutCall = 1;
End;

If Close > sme and putcall > -1 then
Begin
SellShort ("Enter Short") 1 contracts Next bar at market;
PutCall = -1;
End;

End;
The logic is good; this should work.

What is your chart resolution?

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Need some guidance  [SOLVED]

Postby TJ » 08 Aug 2015

ps. The way you code your logic, your PutCall will only work if you have market orders.
If you use stop or limit orders, your fill is not guaranteed, using this logic might give you false positives.

You should get the PutCall status directly from MarketPosition,
then store the value in a variable for easy referencing.
This will prevent any false reading of the trading events.

try this logic:

Code: Select all


vars: PuttCall (0);

if MarketPosition = 1 then PuttCall = 1
else if MarketPosition = -1 then PuttCall = -1;


if MarketPosition = 0 then Begin

If Close > sme and putcall < 1 then
Begin
buy ("Enter Long") 1 contracts Next bar at market;

End;

If Close > sme and putcall > -1 then
Begin
SellShort ("Enter Short") 1 contracts Next bar at market;

End;

End;

Next is to test for timing differences. Make sure you do not double up or reverse your orders on the same bar.


Return to “MultiCharts”