cascade ordering system

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #223879 quote
    ullle73
    Participant
    Senior

    I saw an interesting strategy. I need help coding it, looked really promising.

    Base numbers: Stock ABC is at 100 (attached image for a clearer view)

    • Buy 1 lot when rsi 3 crosses above 70 (follow momentum)
    • Set SL: x points (example 10 points)
    • Set TP y points (example 20 points)
    • If TP is hit, we open lot #2 and move  both SL to 5 points below lot #2 entry (we opened the buy in ABC at 100, moved to our TP at 120, we open lot #2 at 120,  SL for both lots are at 115)
    • If SL is hit, exit all positions
    • If new TP at 140 is hit, open lot #3, set SL for all 3 lots at 5 points below lot #3 entry.
    • Repeat until SL is hit.
    • Reverse the rules for shorts.
    cascade-strategy.jpg cascade-strategy.jpg
    #224330 quote
    ullle73
    Participant
    Senior

    hoping for Roberto to save the day 😀

    #224393 quote
    Monochrome
    Participant
    Senior

    Here’s some code to get started. Courtesy of chatpgt –

     

    // Initial setup
    DEFPARAM CumulateOrders = False // Each order is treated separately
    DEFPARAM FlatAfter = 235900 // Close all positions at the end of the day
    
    // Parameters
    Lot1EntryPrice = 100
    SLPoints = 10
    TPPoints = 20
    SLAdjustment = 5
    LotSize = 1 // Size of each lot
    
    // RSI calculation
    RSI3 = RSI[3](close)
    
    // Conditions
    BuyCondition = RSI3 crosses over 70
    SellCondition = RSI3 crosses under 30
    
    // State variables to keep track of lots
    NumLots = 0
    TotalEntryPrice = 0
    
    // Buying Logic
    IF BuyCondition AND NumLots = 0 THEN
    BUY LotSize CONTRACT AT MARKET
    SetStop = Lot1EntryPrice - SLPoints
    SetTarget = Lot1EntryPrice + TPPoints
    NumLots = 1
    TotalEntryPrice = Lot1EntryPrice
    ENDIF
    
    IF NumLots > 0 AND close >= TotalEntryPrice + (TPPoints * NumLots) THEN
    BUY LotSize CONTRACT AT MARKET
    NumLots = NumLots + 1
    TotalEntryPrice = TotalEntryPrice + close
    SetStop = close - SLAdjustment
    ENDIF
    
    // Selling Logic
    IF SellCondition AND NumLots = 0 THEN
    SELLSHORT LotSize CONTRACT AT MARKET
    SetStop = Lot1EntryPrice + SLPoints
    SetTarget = Lot1EntryPrice - TPPoints
    NumLots = 1
    TotalEntryPrice = Lot1EntryPrice
    ENDIF
    
    IF NumLots > 0 AND close <= TotalEntryPrice - (TPPoints * NumLots) THEN
    SELLSHORT LotSize CONTRACT AT MARKET
    NumLots = NumLots + 1
    TotalEntryPrice = TotalEntryPrice + close
    SetStop = close + SLAdjustment
    ENDIF
    
    // Exiting Logic
    IF (LongOnMarket AND close <= SetStop) OR (ShortOnMarket AND close >= SetStop) THEN
    SELL AT MARKET
    exitSHORT AT MARKET
    NumLots = 0
    TotalEntryPrice = 0
    ENDIF
    robertogozzi thanked this post
    #224396 quote
    PeterSt
    Participant
    Master

    My eye fell on this :

    NumLots = 0
    TotalEntryPrice = 0

    And with this it may have a chance :

    Once NumLots = 0
    Once TotalEntryPrice = 0

    🙂

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

cascade ordering system


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by PeterSt
2 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/18/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...