Indicator: CC_Theodore

0 252 Views No Comments 10 months ago
  • Custom Indicator Command from a Haasonline Original favorite…

    RSI with 3 lengths..

    • This topic was modified 9 months, 3 weeks ago by kobalt.
    HaasScript Code
    -- Define command
    DefineCommand('Theodore', 'Theodore')
    -- Define command parameters.
    local chartIndex = DefineParameter(NumberType, 'chartIndex', 'The index on which to chart', true, 1, 'Number')
    local name = DefineParameter(StringType, 'name', 'Unique name of the indicator.', true, 'Theodore', 'Text')
    local interval = DefineParameter(NumberType, 'interval', 'Used interval for price data. Default is 0 and the main interval will be used.', true, 0, 'Number,InputInterval')
    
    -- Input fields for the indicator.
    InputGroupHeader(''..name..' Settings')
    local d = Input('RSI Length-1',12) 
    local e = Input('RSI Length-2',24) 
    local f = Input('RSI Length-3',32) 
    
    -- This will improve our backtest speed when using the command.
    DefineIntervalOptimization(interval)
    -- Calculate the indicator
    local prices = ClosePrices(interval)
    -- Get the required data
    local p = Prices()          
     
    -- Calculations
    local x = RSI(p, d);           
    local xx = x[1]                
    
    local y = RSI(p, e);           
    local yy = y[1]                
    
    local z = RSI(p, f);           
    local zz = z[1]                
    
    -- Lets draw the lines on the chart
    Plot(1, 'Buy', 30, {c=Green})
    Plot(1, 'Sell', 70, {c=Red})
    
    Plot(1, 'RSI-1', xx, {c=White})
    Plot(1, 'RSI-2', yy, {c=Gray})
    Plot(1, 'RSI-3', zz, {c=DarkGray})
    
    -- Determine the signal.
    local signal = SignalNone
    
    -- Plot the indicator Use the chartIndex parameter.
    
    Plot(1, 'Buy', 30, {c=Green})
    Plot(1, 'Sell', 70, {c=Red})
    
    Plot(1, 'RSI-1', xx, {c=White})
    Plot(1, 'RSI-2', yy, {c=Gray})
    Plot(1, 'RSI-3', zz, {c=DarkGray})
    
    -- Check for a open order
    
    
      if (xx > 70) then
        if (yy > 70) then
          if (zz > 70) then
         local signal =   SignalShort                 -- Signal a sell/short at RSI < 70   
          end
        end
      end
     
      if (xx < 30) then
        if (yy < 30) then
          if (zz < 30) then
          local signal =  SignalLong                  -- Signal a buy/long at RSI > 30  
          end
        end
      end
    
    --Return the custom signal.
    DefineOutput(EnumType, signal, 'Signal result', 'TradeBotContainer, IndicatorContainer, Signal Helpers')
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free