Closed Order Missing πŸ˜‚

Posted By: AdamWu

Closed Order Missing πŸ˜‚ - 07/26/20 00:56

Dear all, I am working on a strategy. Before it start a new position, it will check the latest closed order in the same direction. If the latest closed order in the same direction loose money, no new position will be started. But I found one of the closed order can not be found by:
Code
function lastTradeFail(string direction, int timeDif, bool mute){
	string asset_tmp = Asset;
	for(closed_trades){
		if(strcmp(asset_tmp,"CHF/JPY")==0 && strcmp(Asset,"CHF/JPY")==0 && !mute){	
			printf("\n***********: %s, %.4f, %d, %d",Asset, (var)TradePriceClose, ymd(TradeExitDate), ymd(wdate()));
		}
	}
}

Output of "20200717" (last order start date):
Code
Test: _portfolio4  2020
Assets AssetsFXCMLite_19
Read _portfolio4.fac
Warning 048: trade loop recursion
***********: CHF/JPY, 113.4548, 20200716, 20200717
***********: CHF/JPY, 114.0899, 20200714, 20200717


By comparing the The TradePriceClose and TradeExitDate, I found this order [CHF/JPY::S28133] is missing. This order was recorded in the log file:
Quote

[3281: Thu 20-07-16 14:00] 1994 +22.97 26/19 (113.44)
Warning 048: trade loop recursion
[CHF/JPY::S28133] Short 7@113.45 Risk 24 t at 14:00:00

[3302: Fri 20-07-17 11:00] 1957 +37.26 27/23 (113.84)
[CHF/JPY::S28133] Stop 7@113.91: -24.32


[Linked Image]

After hours of debuging, I don't have a clue any more. Please help ~~~

Attached picture closed_order_missing.JPG
Posted By: AndrewAMD

Re: Closed Order Missing πŸ˜‚ - 07/26/20 01:07

Rewrite your script so that it is not causing trade loop recursion. TLR causes all kinds of nasty side effects.
Posted By: AdamWu

Re: Closed Order Missing πŸ˜‚ - 07/26/20 01:40

Originally Posted by AndrewAMD
Rewrite your script so that it is not causing trade loop recursion. TLR causes all kinds of nasty side effects.

Hi AndrewAMD, thank you for your quick replyπŸ‘. I found out if the checking function (lastTradeFail) return true, and the main process start a new position, then the TLR warning will show up.

Am I wrong in the process?

Code
                if(crossOver(Signal,Threshold)){
			if(Price[0]>MySignal[0] || lastTradeFail("long",3600*24*2,true)==1){
				if(lastTradeFail("short",3600*24*2,false))
					return;
				enterShort();
			}
		}


Attached picture loop_recurision.png
Posted By: AndrewAMD

Re: Closed Order Missing πŸ˜‚ - 07/26/20 12:18

I’d need to see the rest of the script to answer that.

Generally, you get that warning if you either:
* Nest a macro loop inside a macro loop or
* Break from the macro loop without using the macro break.

I’m guessing it’s the latter.
Posted By: AdamWu

Re: Closed Order Missing πŸ˜‚ - 07/26/20 15:11

Originally Posted by AndrewAMD
I’d need to see the rest of the script to answer that.

Generally, you get that warning if you either:
* Nest a macro loop inside a macro loop or
* Break from the macro loop without using the macro break.

I’m guessing it’s the latter.

You are absolutly right. I didn't close the macro loop properly. Thank you so much!πŸ‘πŸ‘πŸ‘

For any newbie like me who have the same problem, the macro loop can be closed like this:
Code
function lastTradeFail(){
	bool res = false;
	for(closed_trades){
		...
		res = true;
		break_trades;
	}
	return res;
}
Posted By: danatrader

Re: Closed Order Missing πŸ˜‚ - 07/26/20 19:28

Originally Posted by AdamWu
[quote=AndrewAMD]

For any newbie like me who have the same problem, the macro loop can be closed like this:


Can you post the complete sample please?
Posted By: AdamWu

Re: Closed Order Missing πŸ˜‚ - 07/27/20 10:46

Hi danatrader, I updated above post to make it more specific. If you want to discuss more about the strategy, Please Please Please join our discussion: https://discord.gg/yfxyrNu
© 2024 lite-C Forums