Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by 7th_zorro. 04/16/24 13:19
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (Ayumi, Quad, rki, 7th_zorro), 482 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
TMF with adapting lots #473070
06/12/18 07:11
06/12/18 07:11
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
With the trailing stop script below I would like to adapt the position size to the TradeStopLimit, however if I define Lots inside the function TrailingStop it is ignored and set to 1, also I do not have access to TradeStopLimit in the run even if it has been set in TrailingStop, it will output 0.
Could you please tell me how I could some this issue please?

int TrailingStop()
{
if(TradeIsLong and TradeProfit > 0)
TradeStopLimit = max(TradeStopLimit, priceLow() - 3 * ATR(20));

if(TradeIsShort and TradeProfit > 0)
TradeStopLimit = min(TradeStopLimit, priceHigh() + 3 * ATR(20));

return 0;
}

static TRADE* MyTrade = NULL;

function run()
{
set(TICKS);

BarPeriod = 1440;
LookBack = 61;
StartDate = 2017;
EndDate = 2018;

Slippage = 0;
Spread = 0;

if(!TradeIsOpen)
{
if(random() < 0)
MyTrade = enterShort(TrailingStop);
else
MyTrade = enterLong(TrailingStop);
}

if (TradeIsOpen)
{
ThisTrade = MyTrade;

printf("nStop = %.5f", TradeStopLimit);
}

set(LOGFILE);
}

Re: TMF with adapting lots [Re: byakuren81] #473077
06/12/18 13:55
06/12/18 13:55
Joined: Feb 2017
Posts: 1,724
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,724
Chicago
A TMF is intended for handling already-open trades. That means lot size was already determined by the time Zorro calls any TMF function.

Ideally, you should size your trade in run() before you call enterShort(TrailingStop) or enterLong(TrailingStop).

Depending on what you are trying to do, maybe you can create a global variable for the next lot size. You can set it from your TMF and get it from run().

Also, this is vague:
Code:
if(TradeIsLong and TradeProfit > 0)

Be explicit and use more parentheses.

Re: TMF with adapting lots [Re: AndrewAMD] #473083
06/12/18 17:36
06/12/18 17:36
Joined: Jan 2014
Posts: 86
London City
B
byakuren81 Offline OP
Junior Member
byakuren81  Offline OP
Junior Member
B

Joined: Jan 2014
Posts: 86
London City
Ouch yep indeed thx for that I should be more careful about the parentheses!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1