progress update on risk code project, all below written by gpt.
Certainly! Here's a code snippet that incorporates a system with inputs for bracket orders, breakeven with transaction cost, and three levels of adjustable trailing stops for profit and stop loss:
powerlanguage
inputs:
EntryPrice(0), // Entry price for the trade
Quantity(1), // Number of contracts to trade
ProfitTargetTicks(10), // Profit target in ticks
StopLossTicks(10), // Initial stop loss in ticks
BreakevenTicks(2), // Number of ticks to trail for breakeven stop
TransactionCost(2), // Transaction cost per contract
TrailingStop1Ticks(10), // Trailing stop level 1 in ticks
TrailingStop2Ticks(20), // Trailing stop level 2 in ticks
TrailingStop3Ticks(30); // Trailing stop level 3 in ticks
vars:
EntryPriceAdjusted(0), // Entry price adjusted for transaction cost
BreakevenTriggered(false), // Flag to track breakeven stop triggered
BreakevenStopPrice(0), // Breakeven stop price
TrailingStop1Triggered(false), // Flag to track trailing stop level 1 triggered
TrailingStop2Triggered(false), // Flag to track trailing stop level 2 triggered
TrailingStop3Triggered(false); // Flag to track trailing stop level 3 triggered
// Adjust entry price for transaction cost
EntryPriceAdjusted = EntryPrice + TransactionCost * MinMove;
// Entry order
Buy("EntryOrder") Quantity shares next bar at EntryPriceAdjusted stop;
// Profit target order
Sell("ProfitTarget") Quantity shares next bar at EntryPriceAdjusted + ProfitTargetTicks * MinMove limit;
// Initial stop loss order
Sell("StopLoss") Quantity shares next bar at EntryPriceAdjusted - StopLossTicks * MinMove stop;
// Breakeven stop logic
if BreakevenTriggered = false and High >= EntryPriceAdjusted + BreakevenTicks * MinMove then
begin
BreakevenStopPrice = EntryPriceAdjusted;
BreakevenTriggered = true;
end;
if BreakevenTriggered then
Sell("BreakevenStop") Quantity shares next bar at BreakevenStopPrice stop;
// Trailing stop logic
if Low <= EntryPriceAdjusted - TrailingStop1Ticks * MinMove then
TrailingStop1Triggered = true;
if TrailingStop1Triggered then
Sell("TrailingStop1") Quantity shares next bar at Lowest(Low, 1) + TrailingStop1Ticks * MinMove stop;
if Low <= EntryPriceAdjusted - TrailingStop2Ticks * MinMove then
TrailingStop2Triggered = true;
if TrailingStop2Triggered then
Sell("TrailingStop2") Quantity shares next bar at Lowest(Low, 1) + TrailingStop2Ticks * MinMove stop;
if Low <= EntryPriceAdjusted - TrailingStop3Ticks * MinMove then
TrailingStop3Triggered = true;
if TrailingStop3Triggered then
Sell("TrailingStop3") Quantity shares next bar at Lowest(Low, 1) + TrailingStop3Ticks * MinMove stop;
In this code snippet, the inputs allow you to specify the entry price, quantity, profit target, stop loss, breakeven, transaction cost, and three levels of trailing stops. The entry order, profit target order, and initial stop loss order are placed based on the specified inputs.
The code also includes logic for the breakeven stop, where the breakeven stop price is triggered when the high reaches a specified number of ticks above the entry price. Additionally, there are trailing stop levels that are triggered when the low reaches a certain distance below the entry price.
Please note that this is a simplified example, and you may need to further customize and adapt the code to your specific trading strategy and platform. Also, ensure to thoroughly test and validate the strategy before using it in live trading, considering the potential risks and transaction costs involved.