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();
}

Last edited by SnoopySniff; 02/22/19 11:10.