Hello everyone,
I’m trying a simple autotrading strategy with PRT Bands, just to test it (I’m using IB), but I don’t understand why it works correctly in backtest but not in DEMO. In Demo it doesn’t open positions, anyone can help me why, please? I’ve got a strategy on gold that works, now I’m testing the strategy on large stocks (Tesla and Nvidia) , but for some reason it doesn work. I’m thinking if the problem is the fact it buys at market and not with limit order?
thank’s anyone in advance who can help me.
//-------------------------------------------------------------------------
// Main code : Nuovo3
//-------------------------------------------------------------------------
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
EXP1 = ExponentialAverage[1](close)
up = PRTBANDSUP
dn = PRTBANDSDOWN
EXP50 = ExponentialAverage[50](close)
EXP100 = ExponentialAverage[100](close)
c2 = (EXP50 >= EXP100)
c3 = (EXP100 >= EXP50)
if close crosses over up and trend<=0 then //prezzo supera banda superiore
trend=1
elsif close crosses under dn and trend>=0 then //prezzo ribassa banda inferiore
trend=-1
ENDIF
c4 = trend<>trend[1]
//condizione per entrare Long
IF NOT longonmarket and Trend=1 and c2 and c4 then
BUY 10 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
IF longonmarket and TREND=-1 and c4 THEN
SELL AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 4
I want to specify that the working strategy on gold is not the same.
I’m thinking if the problem is the fact it buys at market and not with limit order?
I think you showed the wrong code because it shows with Market Orders ?
With Demo you mean the PaperTrading option at startup ?
Might be a margin requirement? 10 shares of large stocks could be too much for your account size/margin
Yes I mean paper trading. ISn’t correct to use Market order in DEMO? I saw it works for gold (but it’s another strategy). by the way my doubt was another one. Since that during pre market and after market you can enter long only with limit order, is it correct to use “Buy at Market” ? I don’t think that is the problem because I verified that the condition to enter was activeted during regular hours.
Hi Nicolas,
my DEMO account has 25K. 10 shares of a stock whose value is 150 $, I don’t believe that could be a problem. COuld be because IB does work only in a limited choiches so far?
JSParticipant
Senior
What kind of time frame do you use for this code?
I don’t know how long you ran this code in demo but it may take a while for a position to open…
I use 1H timeframe. For example yesterday should be have gone long but it didn’t. in my backtest it did (in attachment)
JSParticipant
Senior
In your attachment (pdf) a position was opened on March 2… (a week ago)…?
strategy was lunched on 4th of march, in attachment you see the chart of the strategy where there are no positions open, on the right chart the backtest. As you can see a position should be opened but there is nothing. I cannot explain. someone can understand why?
Are you using the same value for Spread in the Backtest as will be used during Live running?
thank you Graha, that could be problem in fact