Hi,
My strategy below is opening correctly but not setting a stop – I am just wondering if anyone could tell me why the stop is blank when it opens. It seems to work on back testing:
c1 = (low < indicator1)
c2 = close > midPrev
c3 = (BBwidth > 50)
c4 = (open[1] > close[1]) and rangeprevious > 3
c5 = (indicator2 > 33)
c6 = ( (Average[20](close) - 2 * Std[20](close)) - low ) > 8
c7 = (Close - open) > 20
c8 = (Close - open) < 30
IF (c1 and c2 AND c3 and c4 and c5 and c6 and c7 and c8) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
buy 5 PERPOINT AT MARKET
entryLow = low // Store the low of the candle before the entry candle
endif
// Exit condition
if onmarket then
// Exit at the low of the candle before the entry candle
sell at entrylow stop
SET TARGET PROFIT 45
Hi,
The missing ENDIF you showed would actually throw a compilation error, so I assume your real code has it and was just cut off when pasting here.
Without seeing your full code (including how indicator1, indicator2, midPrev, BBwidth, rangeprevious and the time/day filters are defined) we can’t reproduce the issue.
I’ve tested a simplified version replicating your exact structure with standard indicators, and the stop works correctly in backtesting.
Could you please share the complete code? That way we can properly investigate why the stop appears blank in live execution.
In the meantime, you can add this line to your backtest version to visually confirm the stop level:
GRAPHONPRICE entryLow
This will draw the stop level on the chart. Remove it before running live.
On what timeframe do you launch the strategy on please?
If the Low is too close of the order opening price, the broker might reject it due to minimum stop distance.
However, try to use this way of setting the stop at a direct price, with SET STOP PRICE:
c1 = (low < indicator1)
c2 = close > midPrev
c3 = (BBwidth > 50)
c4 = (open[1] > close[1]) and rangeprevious > 3
c5 = (indicator2 > 33)
c6 = ( (Average[20](close) - 2 * Std[20](close)) - low ) > 8
c7 = (Close - open) > 20
c8 = (Close - open) < 30
IF (c1 and c2 AND c3 and c4 and c5 and c6 and c7 and c8) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
buy 5 PERPOINT AT MARKET
entryLow = low // Store the low of the candle before the entry candle
SET STOP PRICE entryLow
SET TARGET PROFIT 45
endif
This is the full code below. But it is happening with all my codes that have a similar stop…..when I have queried it they have simply told me, your code doesnt have a stop. On this code it is opening trades without a target and without a stop.
// Main code : us tech
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
DEFPARAM FLATBEFORE = 143000
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 213000
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 143000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 210000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Defining bollinger band width
mid = Average[20](close)
upper = mid + 2.0* Std[20](close)
lower = mid - 2.0* Std[20](close)
BBwidth = upper - lower
// Defining mid of previous candle
midPrev = (open[1] + close[1]) / 2
condition = close > midPrev
//Definitition of previous candle
prevBody = close[1] - open[1]
//Bollinger band definition
mid = Average[20](close)
lower = mid - 2 * Std[20](close)
upper = mid + 2 * Std[20](close)
condition = (lower - low) > 4 // low is more than 4 below the lower band
// Conditions to enter long positions
indicator1 = BollingerDown[20](close)
indicator2 = RSI[14](close)
indicator3 = BollingerUp[20](close)
rangeprevious = Open[1] - close[1]
c1 = close - open > 60
c2 = close[1] < open[1] and close[2] < open[2] and close[3] < open[3]
c3 = close > open[1] and close > open[2] and close > open[3] and close > open[4]
c4 = high - close < 20
c5 = close -low < 172
c6 = low < low[1]
IF (c1 and c2 AND c3 and c4 and c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
buy 2 PERPOINT AT MARKET
entryLow = low // Store the low of the candle before the entry candle
endif
// Exit condition
if onmarket then
// Exit at the low of the candle before the entry candle
sell at entrylow stop
SET TARGET PROFIT 100
ENDIF
@tradermaker, the reason your live trades open without stop/target is that:
- entryLow is set when the order condition is true, but you only place the stop and target one bar later inside IF ONMARKET THEN.
- On the entry bar, the order is still a pending market order until the bar closes, so ProOrder does not yet know you are ONMARKET and does not send any stop/target at that time.
- On the next bar, entryLow may already have changed (because you overwrite it every time the condition is true), or the condition never runs again, so the stop level is inconsistent or missing.
Solution: set the stop and target immediately when you send the market order, and protect entryLow with NOT LONGONMARKET so it is not overwritten after entry.
Corrected version of your code (core part only):
// Main code : us tech
DEFPARAM CumulateOrders = False
DEFPARAM FLATBEFORE = 143000
DEFPARAM FLATAFTER = 213000
noEntryBeforeTime = 143000
timeEnterBefore = time >= noEntryBeforeTime
noEntryAfterTime = 210000
timeEnterAfter = time < noEntryAfterTime
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Bollinger band width
mid = Average[20](close)
upper = mid + 2.0* Std[20](close)
lower = mid - 2.0* Std[20](close)
BBwidth = upper - lower
// Mid of previous candle
midPrev = (open[1] + close[1]) / 2
condition = close > midPrev
// Previous candle body
prevBody = close[1] - open[1]
// Bollinger band (again, could be removed as duplicate)
mid = Average[20](close)
lower = mid - 2 * Std[20](close)
upper = mid + 2 * Std[20](close)
condition = (lower - low) > 4
// Indicators & conditions
indicator1 = BollingerDown[20](close)
indicator2 = RSI[14](close)
indicator3 = BollingerUp[20](close)
rangeprevious = open[1] - close[1]
c1 = close - open > 60
c2 = close[1] < open[1] and close[2] < open[2] and close[3] < open[3]
c3 = close > open[1] and close > open[2] and close > open[3] and close > open[4]
c4 = high - close < 20
c5 = close - low < 172
c6 = low < low[1]
// --- ENTRY BLOCK: send order + stop + target on the same bar ---
IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND NOT daysForbiddenEntry AND NOT LONGONMARKET THEN
// Store the low of the entry candle only once, at entry
entryLow = low
// Send the market order
BUY 2 PERPOINT AT MARKET
// Attach stop and target immediately
SELL AT entryLow STOP
SET TARGET PROFIT 100
ENDIF
// --- EXIT SAFETY BLOCK: re-apply stop/target every bar while in position ---
IF ONMARKET THEN
// Re-assert the same stop level and target while the position is open
SELL AT entryLow STOP
SET TARGET PROFIT 100
ENDIF
Logic explained:
- NOT LONGONMARKET in the entry block:
- Ensures entryLow is only set once, on the actual entry candle.
- Prevents entryLow from being updated on later candles while you are already in a trade.
- Inside the same IF as the BUY … AT MARKET, you immediately place:
- SELL AT entryLow STOP → explicit stop-loss level is sent with the order.
- SET TARGET PROFIT 100 → profit target distance is also attached right away.
- The second IF ONMARKET block:
- Re-applies the same stop and target every bar as a safety net, so if for any reason they get cancelled or modified by the broker, ProOrder keeps sending them while the position is open.
If your broker has a minimum stop distance and entryLow is too close to the entry price, the server can still reject the stop; in that case you will see no stop in the position window even though the strategy is syntactically correct. In such a case you may need to use a slightly further price (e.g. entryLow – 5 points) or SET STOP PRICE with a valid distance.
Hi,
May i know which AI you guys recommend to write up Strategy?
I’ve used Google AI, DeepSeek and they seems buggy.
Eg, When i do a fixed 100 points at 1 contract Stop Loss, there are closed trades with losses more than 100. eg 500. “(