Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, dBc), 18,430 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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,806
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,806
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