- ago
CODE:
using WealthLab.Core; using WealthLab.Backtest; using WealthLab.Indicators; public class EstrategiaCorrigida : UserStrategyBase {    public EstrategiaCorrigida() : base()    {       StartIndex = 5;       PositionSize = new ConstantPositionSize(100); // Instância correta    }    public override void Execute(BarHistory bars, int bar)    {       if (bar != 4) return;       // Correção na máxima e mínima       double max = Highest.Series(bars.High, 4)[bar];       double min = Lowest.Series(bars.Low, 4)[bar];       double amplitude = max - min;       double fechamento = bars.Close[bar];       int totalPos = (int)PositionSize.GetPositionSize(bars, bar);       int lote70 = (int)(totalPos * 0.7);       int lote30 = totalPos - lote70;       if (fechamento > max)       {          PlaceTrade(bars, bar, TransactionType.Buy, OrderType.Market, lote70);          PlaceTrade(bars, bar + 1, TransactionType.Sell, OrderType.Limit, fechamento + amplitude, lote70);          PlaceTrade(bars, bar + 1, TransactionType.Sell, OrderType.Stop, min, lote70);          PlaceTrade(bars, bar, TransactionType.Buy, OrderType.Market, lote30);          PlaceTrade(bars, bar + 1, TransactionType.Sell, OrderType.Limit, fechamento + (amplitude * 2), lote30);          PlaceTrade(bars, bar + 1, TransactionType.Sell, OrderType.Stop, min, lote30);       }       else if (fechamento < min)       {          PlaceTrade(bars, bar, TransactionType.Short, OrderType.Market, lote70);          PlaceTrade(bars, bar + 1, TransactionType.Cover, OrderType.Limit, fechamento - amplitude, lote70);          PlaceTrade(bars, bar + 1, TransactionType.Cover, OrderType.Stop, max, lote70);          PlaceTrade(bars, bar, TransactionType.Short, OrderType.Market, lote30);          PlaceTrade(bars, bar + 1, TransactionType.Cover, OrderType.Limit, fechamento - (amplitude * 2), lote30);          PlaceTrade(bars, bar + 1, TransactionType.Cover, OrderType.Stop, max, lote30);       }    } }
0
157
2 Replies

Reply

Bookmark

Sort
- ago
#1
Well, you shouldn't blindly trust ChatGPT or whatever AI you're using since it's hallucinating on PositionSize.
0
- ago
#2
Honestly, I would start with one of the example C# strategies that compiles then work from there.

Looking at this code, I can't even figure out what it's trying to do. It's missing the required Initialize{block}. It's adding parameters to the PlaceTrade method that shouldn't even be there. And there's no such class as ConstantPositionSize.
0

Reply

Bookmark

Sort