1 registered members (AndrewAMD),
559
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[SOLVED]-Trades closing themselves?! (and opening in odd places)
#467005
07/12/17 02:38
07/12/17 02:38
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Hi all, OK, they are most likely not closing themselves but I can't put my finger on what the issue is. The strategy is simple enough and based on price levels. Once price is inside the upper/lower zone, it places a sell/buy below/above the zone by a certain number of pips. Trades are meant to stay open until TP or the end of the test period. The code:
//----globals
if(is(INITRUN))
{
var sixthLen = 1682;
var splitBy = 6;
//var TP = 50*PIP; //takeprofit in pips converted to price value
//var buffer = 10*PIP; //distance from market for pendings to be placed
var tradeLim = 2000;
}
//----sixths functions
var sixthHigh(period, splitBy)
{
return (HH(period) - ((HH(period)-LL(period))/splitBy));
}
var sixthLow(period, splitBy)
{
return (LL(period) + ((HH(period)-LL(period))/splitBy));
}
//----order functions
function CheckForTradeOpportunity()
{
var TP = 50*PIP; //takeprofit in pips converted to price value
var buffer = 10*PIP; //distance from market for pendings to be placed
vars Price = series(priceClose()); //create the price series for the selected asset
EntryTime = 10000000;
//check to see if we can enter long
if(NumOpenLong + NumPendingLong < tradeLim)
{
if(crossUnder(Price, sixthLow(sixthLen, splitBy))) //> need to change this to a comparative function or add another block for non cross events
{
enterLong(0, sixthLow(sixthLen, splitBy) + buffer, 0, TP);
printf("nprice = %.5f, sixthsLow = %.5f, pending price = %.5f", price(), sixthLow(sixthLen, splitBy), sixthLow(sixthLen, splitBy) + buffer);
}
}
//check to see if we can enter short
if(NumOpenShort + NumPendingShort < tradeLim)
{
if(crossOver(Price, sixthHigh(sixthLen, splitBy)))
{
enterShort(0, sixthHigh(sixthLen, splitBy) - buffer, 0, TP);
printf("nprice = %.5f, sixthsHigh = %.5f, pending price = %.5f", price(), sixthHigh(sixthLen, splitBy), sixthLow(sixthLen, splitBy) + buffer);
}
}
}
//----main exectution block, comparable to OnTick()
function run()
{
set(LOGFILE);
BarPeriod = 60;
LookBack = sixthLen;
//PlotBars = 500;
StartDate = 2012;
EndDate = 2017;
Hedge = 2; //allows full hedging, default = 0 -> no hedgintg
CheckForTradeOpportunity();
//--------------
plot("Lowest", LL(sixthLen), 0, BLACK);
plot("Highest", HH(sixthLen), 0, BLACK);
plot("upperTZ", HH(sixthLen) - ((HH(sixthLen)-LL(sixthLen))/splitBy), 0, RED);
plot("lowerTZ", LL(sixthLen) + ((HH(sixthLen)-LL(sixthLen))/splitBy), 0, RED);
set(PLOTNOW);
}
Inspecting the resulting plot reveals there are trades closing at a loss before the simulation is over. I'm not sure why and it is likely some default global I'm not aware of despite having found and checked it in the manual. Any ideas? Cheers, BobbyT EDIT: changed the start/end period to highlight another problem. There are trades being placed at what appears to be erroneous prices. Check the plot in the first half of July 2010. There is a trade that has opened at the peak of a small rally. This trade is well outside of the trade zone (both upper and lower zones). This is easily seen against the red channel which marks out the inner boundary of the trade zone. I'm taken aback by the amount of teething problems I'm having switching over to Zorro. Having said that, the platforms I'm familiar with have massive user bases and chances are if you have a problem you can normally find info about it somewhere. Alas, Zorro is still growing. So I have to bother you poor sods if I need help. Sorry (these posts will get more interesting with time but at this stage I'm still learning to crawl before I can walk in Zorro land)
Last edited by BobbyT; 07/18/17 03:31.
|
|
|
Re: Trades closing themselves?! (and opening in odd places)
[Re: jcl]
#467025
07/12/17 18:34
07/12/17 18:34
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Hi JCL, That is always true. until it isn't That's exactly the thing, the trades are never meant to exit. It's a bad strategy but one that I though would allow me to become familiar with the platform. After the finding that pending orders are deleted after one bar if they aren't filled, I thought maybe there was something that I had missed in the default global variables that may be causing the issue. Regardless, I have added print statements which return the entry price and indicator price for each trade and the indicator price always seems to be correct. So I am at a loss as to what the issue is. I will check out the debug mode to see if I can pick up the issue as it steps through the simulation. But...don't be surprised if you see me back here in the next couple of days whining about the same problem Cheers, BobbyT
Last edited by BobbyT; 07/12/17 18:36.
|
|
|
Re: Trades closing themselves?! (and opening in odd places)
[Re: Mithrandir77]
#467034
07/13/17 02:22
07/13/17 02:22
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Hi Mithrandir, Thanks for the reply. I tried
printf(TO_LOG,"nStuff", SomeVariables);
but it throws a crash error (#111) when it tries to print those statements. I tried replacing my desired statements with
printf(TO_LOG, "ntest message");
which results in the same crash error. I had also previously tried short-cutting it to the log with
printf(TO_LOG, "#ntest message");
this runs, but results in messages not being printed to the log after a couple of months. The above examples were appended immediately after the enterLong/Short calls. Cheers, BobbyT EDIT: forgot about the forum editing out slashes from text. In all the examples there is a backslash before the 'n' (between the # and 'n' in the third example)
Last edited by BobbyT; 07/13/17 02:23.
|
|
|
|