Labelling an Exit for Better Optimization
Labelling an Exit for Better Optimization
18 Dec 2024, 11:57
Hi,
I have a bot that will be using various moving averages as the exit criteria.
Below are the exit lines that will be running during the back testing, but I want to be able to determine which moving average provides the best result.
Is there a way to use a label so in the events tab, after running optimization, I can see which MA's performed the best by seeing the actual MA type as the label instead of just seeing ‘position closed’ and not knowing which ExitMA was actually triggered?
Any help would be GREATLY appreciated!
Thank you.
private void Exit1(int index1)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index1] < _ExitMA1.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index1] > _ExitMA1.Result.LastValue))
ClosePosition(position);
}
}
private void Exit2(int index2)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index2] < _ExitMA2.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index2] > _ExitMA2.Result.LastValue))
ClosePosition(position);
}
}
private void Exit3(int index3)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index3] < _ExitMA3.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index3] > _ExitMA3.Result.LastValue))
ClosePosition(position);
}
}
private void Exit4(int index4)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index4] < _ExitMA4.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index4] > _ExitMA4.Result.LastValue))
ClosePosition(position);
}
}
private void Exit5(int index5)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index5] < _ExitMA5.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index5] > _ExitMA5.Result.LastValue))
ClosePosition(position);
}
}
private void Exit6(int index6)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index6] < _ExitMA6.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index6] > _ExitMA6.Result.LastValue))
ClosePosition(position);
}
}
private void Exit7(int index7)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index7] < _ExitMA7.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index7] > _ExitMA7.Result.LastValue))
ClosePosition(position);
}
}
private void Exit8(int index8)
{
{
var positions = Positions.FindAll(InstanceName, SymbolName);
foreach (var position in positions)
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index8] < _ExitMA8.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index8] > _ExitMA8.Result.LastValue))
ClosePosition(position);
}
}
Replies
thecaffeinatedtrader
25 Dec 2024, 11:53
RE: Labelling an Exit for Better Optimization
PanagiotisCharalampous said:
Hi there,
Where exactly do you want to see this information? In the log?
Best regards,
Panagiotis
Hi,
I would like to view this after optimization in the events tab. But with that said, I don't know if this is even an option do.
Currently it displays 4 event types,
- Create Position
- Take Profit Hit
- Stop Loss Hit
And the one related to the MA Exit criteria displays as:
4. Position Closed
But in doing so, does not tell me which MA Type was actually triggered.
Please let me know if this is possible or if there is a way you would recommend so I can see which MA's perform the best in use of an exit criteria so I can eliminate one's that underperform and keep the one's that do and re-run the optimization accordingly.
Thank you!
@thecaffeinatedtrader
PanagiotisCharalampous
27 Dec 2024, 08:21
RE: RE: Labelling an Exit for Better Optimization
thecaffeinatedtrader said:
PanagiotisCharalampous said:
Hi there,
Where exactly do you want to see this information? In the log?
Best regards,
Panagiotis
Hi,
I would like to view this after optimization in the events tab. But with that said, I don't know if this is even an option do.
Currently it displays 4 event types,
- Create Position
- Take Profit Hit
- Stop Loss Hit
And the one related to the MA Exit criteria displays as:
4. Position ClosedBut in doing so, does not tell me which MA Type was actually triggered.
Please let me know if this is possible or if there is a way you would recommend so I can see which MA's perform the best in use of an exit criteria so I can eliminate one's that underperform and keep the one's that do and re-run the optimization accordingly.Thank you!
Hi there,
You can't modify what is written in the Events tab. You can only print information in the Log. Ideally you should use it to print the information that is meaningful to you.
Best regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
19 Dec 2024, 06:59
Hi there,
Where exactly do you want to see this information? In the log?
Best regards,
Panagiotis
@PanagiotisCharalampous