TradeVars not working with pending trades

Posted By: SnoopySniff

TradeVars not working with pending trades - 02/21/19 14:01

I need to store some parameters for pending trades. I am using for this the TradeVar's. But unfortunately the TradeVar are not keeping the values. With open trades it's working but not with pending trades.

I tried to assign the pending trade to the ThisTrade variable. But when I do so my script is crashing.

ThisTrade = enterLong(1, -2*PIP);

What can I do?
Posted By: Spirit

Re: TradeVars not working with pending trades - 02/21/19 17:06

Find why it does not work or crash, then make it work and fix the crash. ThisTrade is zero when the enterLong failed.

https://manual.zorro-project.com/trouble.htm

BTW, its the 3rd time I had to move your topic. Please post such questions here in Starting. Not in the Scripts forum. That is for working scripts only.
Posted By: SnoopySniff

Re: TradeVars not working with pending trades - 02/22/19 10:09

Originally Posted By: Spirit
Find out why it does not work or does crash, then make it work and fix the crash. ThisTrade is zero when the enterLong failed.

https://manual.zorro-project.com/trouble.htm

BTW, its the 3rd time I had to move your topic. Please post such questions here in Starting. Not in the Scripts forum. That is for working scripts only.


I am sorry. I didn't know that you were moving my topics. I thought I put it here by mistake and so I moved it back.

I am working on finding out why it's not working. I am investing hours for that. Believe me I don't try to make it easy for me.
Posted By: Spirit

Re: TradeVars not working with pending trades - 02/22/19 10:21

It can be easier when you post your script when asking for help with it. Otherwise no one can see whats wrong. You get then only advices like "find the bug and fix it".
Posted By: SnoopySniff

Re: TradeVars not working with pending trades - 02/22/19 11:09

Originally Posted By: Spirit
It can be easier when you post your script when asking for help with it. Otherwise no one can see whats wrong. You get then only advices like "find the bug and fix it".


I get it. Here it comes! I appreciate it!

When I use the TradeVar's for the pending trades my script crashes.

-------
// This is the error message:

MyCode4Forum compiling............
##### priceClose 0.00000, myATR 0.00051, Spread 0.00001, EntryLong -0.00051, EntryShort -0.00051

--> enterLong EUR/USD pending at -0.00051

--> enterShort EUR/USD pending at -0.00051
Error 111: Crash in function: algo_crashes() at bar 0

-------
// This is the script tailored to the error I get.

#define MyEntryPrice TradeVar[0]
#define MyTradeSetBreakEven TradeVar[1]

function algo_crashes() {

var myATR = 5*PIP+Spread;
var myEntryPriceLong = myATR*-1;
var myEntryPriceShort = myATR*-1;

printf("n ##### priceClose %.5f, myATR %.5f, Spread %.5f, EntryLong %.5f, EntryShort %.5f", priceClose(0), myATR, Spread, myEntryPriceLong, myEntryPriceShort);

if(NumOpenLong == 0 && NumPendingLong == 0 ) {
printf("nn --> enterLong %s pending at %.5f", Asset, myEntryPriceLong);

ThisTrade = enterLong(1, myEntryPriceLong, myATR, 0, Spread);
// MyEntryPrice = myEntryPriceLong; // I quoted it because the script would crash here.
// MyTradeSetBreakEven = 0;

}

if(NumOpenShort == 0 && NumPendingShort == 0) {
printf("nn --> enterShort %s pending at %.5f", Asset, myEntryPriceShort);

ThisTrade = enterShort(1, myEntryPriceShort, myATR, 0, Spread);
MyEntryPrice = myEntryPriceShort; // The script is crashing here. When I quote it there is no crash.
MyTradeSetBreakEven = 0;

}
}

function run() {

if(is(INITRUN)) {

Verbose = 3;

Capital = 1000;
Balance = slider(1,1000,1,1000,"Balance","Balance");
// LookBack = 150;

StartDate = 20190214;
EndDate = 20190214;
BarPeriod = 1;
EntryTime = 1*60*24*5;

set(LOGFILE+TESTNOW+TICKS);
UpdateDays = -1;

Hedge = 2;

}
algo_crashes();
}
Posted By: Spirit

Re: TradeVars not working with pending trades - 02/22/19 11:15

Yes this will crash. when you look on the troubleshooting page under "crash" you see that its the third most frequent beginners mistake listed there.

The fix:

Code:
ThisTrade = enterShort(1, myEntryPriceShort, myATR, 0, Spread);
if(ThisTrade) {
  MyEntryPrice = myEntryPriceShort; // The script is crashing here. When I quote it there is no crash.
  MyTradeSetBreakEven = 0;
}

Posted By: SnoopySniff

Re: TradeVars not working with pending trades - 02/22/19 18:46

Originally Posted By: Spirit
Yes this will crash. when you look on the troubleshooting page under "crash" you see that its the third most frequent beginners mistake listed there.

The fix:

Code:
ThisTrade = enterShort(1, myEntryPriceShort, myATR, 0, Spread);
if(ThisTrade) {
  MyEntryPrice = myEntryPriceShort; // The script is crashing here. When I quote it there is no crash.
  MyTradeSetBreakEven = 0;
}



Yes, it's working when I am starting the script in "Trade"-Mode. But it differs from the Test-Mode. In the Test-Mode the lines in the If-Statement are skipped. In Trade-Mode they are executed. That's what I need. But it's confusing. It's not logic to me but working. Is it perhaps because of there is just a TradeID when the trade is opened with the broker which is not happening in Test-Mode?
Posted By: jcl

Re: TradeVars not working with pending trades - 02/23/19 07:17

ThisTrade is valid or not when the trade was entered or not. It has nothing to do with pending or trade mode, but with market hours or lookback periods. Please read about enterLong in the manual, and read also the troubleshooting page. There you can learn to see what your script is doing - it will make life much easier when you're not helpless in such a situation.
Posted By: SnoopySniff

Re: TradeVars not working with pending trades - 02/25/19 23:00

Thank you, jcl. Sometimes I read it and later I read it and I understand something new. Sometimes I read the solution but I don't perceive it. It's like I can't see the single tree because of the wood. So, sorry for sometimes asking stupid basic beginner stuff. But I am getting better and now I got it and solved all my troubles. :-)
© 2024 lite-C Forums