Buy at current bar and not at next bar open

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5664 quote
    bewise
    Participant
    New

    Hi, I am fairly new to coding on ProRealCode, I want to initiate a buy/sell not at the next bar open but at the current bar, would be great to have some advice.

     

    Thanks

    Eugene

    #5668 quote
    Nicolas
    Keymaster
    Master

    Hello Eugene,

    Unfortunately, it is not possible at the moment to do this. Each condition are tested once a bar. Sorry.

    Do you have any other question about coding? Don’t hesitate to create new topics in forums for specific question about prorealtime coding 🙂

    #5692 quote
    bewise
    Participant
    New

    Thanks Nicolas,

    I am trying to trade 30min, using the bollinger band. Any spikes above the bollinger to take a reversal trade on the same bar, both on the long and short side. Can someone help me see what’s wrong with my code (below)? The backtest does not show the trades according to my thought process. Sometimes it opens where I see the price overshoots the bollinger, and sometimes it does not open a trade where I see the spike.

    Ideally, this strategy uses the same (current) bar to get the signal and to open the trade but not the next open bar.

    Appreciate any help here.

    Tks.

    —————————————————————————————————————————————————-

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    Boll = 20
    
    // Conditions to enter long positions
    indicator1 = high
    indicator2 = BollingerDown[Boll](close)
    c1 = (indicator1 < indicator2)
    
    IF c1 THEN
     BUY 1 CONTRACT AT MARKET
    
    Endif
    
    // Conditions to enter short positions
    indicator5 = close
    indicator6 = BollingerUp[Boll](close)
    c3 = (indicator5 > indicator6)
    
    IF c3 THEN
     SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    SET TARGET $PROFIT 1
    #5700 quote
    Nicolas
    Keymaster
    Master

    You are here testing a high spike below the bollinger bands for a long position. You should use “low” in your indicator1 variable in my opinion.

    And use “high” instead of close in indicator5.

    Also, actually you are testing a spike out of the bollinger bands and not a re-entry in them… it maybe filter some bad signals ..

    Your target profit of 1$ is very minimalist and you don’t even exit position in loss, how do you manage that? because there will be some trades that will never be in gain 🙂

    #5748 quote
    bewise
    Participant
    New

    Tks Nicolas,

    Makes a lot of sense, I somehow didi;t see the obvious where there should be a low, for the buy signal and a high for the sell signal.

    I am trying to trade/scalp the current bars, but unfortunately it is only for the next bar open. Is there a way to trigger the execution at the current bar?

    Tks

    #5749 quote
    Adolfo
    Participant
    Senior

    Hi, i developed my code to buy and sell when the price touch MA, i did it with a LIMIT order when conditions are true, when signal is = 1, then the system sets up a limit order  ready to go :). Also works with an STOP order.

    REM ALEX v.0.2 @Binomio Trading Abril 2016
    REM Estrategia ProOrder ProRealTime
    
    REM No acumular órdenes
    DEFPARAM CumulateOrders=False
    
    REM Horario de operativa
    DEFPARAM FlatBefore = 153000
    DEFPARAM FlatAfter = 212900
    
    REM Variables
    mm = average[8](close)
    uma = Highest[8](high)
    umb = Lowest[8](low)
    
    REM Establecemos nuevo mínimo en movimiento bajista
    if umb<mm and high<mm then
    umb=Lowest[8](low)
    endif
    if high>mm then
    umb=mm
    endif
    
    REM Establecemos nuevo máximo en movimiento alcista
    if uma>mm and low>mm then
    uma=Highest[8](high)
    endif
    if low<mm then
    uma=mm
    endif
    
    REM Establecimiento del ultimo toque con la media móvil
    if barindex<2 then
    ltp = mm
    endif
    if(High[1]>mm[1] and Low[1]<mm[1]) then
    ltp = mm[1]
    endif
    
    REM Condición de entrada Largo
    if (uma-ltp)>objetivo and uma>mm then
    compra=1
    endif
    if (uma-ltp)<=objetivo then
    compra=0
    endif
    
    REM Condición de entrada corto
    if (ltp-umb)>objetivo and umb<mm then
    venta=1
    endif
    if (ltp-umb)<=objetivo then
    venta=0
    endif
    
    REM GESTION MONETARIA
    REM Cálculo de contratos a operar
    initLOT = 1
    stepPROFIT = 400*PointValue
    myLOT = max(initLOT,initLOT+ROUND((strategyprofit-stepPROFIT)/stepPROFIT))
    
    REM Anticipación a la media móvil en la entrada
    plusL = mm - mm[1]
    plusC = mm[1] - mm
    preciocompra = mm+plusL
    precioventa = mm-plusC
    
    REM Bloqueo de apertura de posiciones en la vela siguiente a cierre
    LastTrade = BarIndex - TradeIndex
    
    REM Establecer PROFIT Y STOPS
    REM PROFIT LARGO
    ProfitL = ((uma-ltp)*0.4)
    
    REM PROFIT CORTOS
    ProfitC = ((ltp-umb)*0.25)
    
    REM STOP LARGOS
    StopL = ((uma-ltp)*0.75)
    
    REM STOP CORTOS
    StopC = ((ltp-umb)*0.75)
    
    REM Entrada de posiciones largas
    IF NOT LongOnMarket AND NOT ShortOnMarket AND compra=1 and lasttrade>1 then
    BUY myLOT SHARE AT preciocompra LIMIT
    SET STOP ploss StopL
    SET TARGET pPROFIT ProfitL
    ENDIF
    
    REM Entrada de posiciones cortas
    IF NOT ShortOnMarket AND NOT LongOnMarket AND venta=1 and lasttrade>1 THEN
    SELLSHORT myLOT SHARE AT precioventa LIMIT
    SET STOP pLOSS StopC
    SET TARGET pPROFIT ProfitC
    ENDIF
    
    REM DISTANCIA OBJETIVO MOVIMIENTO DEL PRECIO:
    objetivo=45
    

     

    Hope it helps you!

    Cheers!

    #8752 quote
    mvajdi
    Participant
    Junior

    Hi Adolfo,

    Thank you for sharing your code. I am new in coding and wandered to use your code on  “Perpoint”  instead of “Share” which parts has to be changed?

     

    Thanks

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Buy at current bar and not at next bar open


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bewise @bewise Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by mvajdi
9 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/19/2016
Status: Active
Attachments: No files
Logo Logo
Loading...