chop vs trend strategy help needed..

Forums ProRealTime English forum ProBuilder support chop vs trend strategy help needed..

Viewing 7 posts - 1 through 7 (of 7 total)
  • #242026

    Hi all, I am getting error when running this code on thinkorswim with the message as “expected double when decleraing time variable;

    declare lower;

    # User inputs
    input fastLength = 12;
    input slowLength = 50;
    input endHour = 9;
    input endMinute = 30;

    # Variables for current time
    def currentHour = GetHour(); # Retrieves the current hour of the bar
    def currentMinute = GetMinute(); # Retrieves the current minute of the bar

    # Determine premarket status
    def isPremarket = if currentHour < endHour or (currentHour == endHour and currentMinute <= endMinute) then 1 else 0;

    # Variables for premarket high and low
    rec premarketHigh = if isPremarket then Max(high, premarketHigh[1]) else premarketHigh[1];
    rec premarketLow = if isPremarket then Min(low, premarketLow[1]) else premarketLow[1];

    # Trend functions
    def fastEMA = ExpAverage(close, fastLength);
    def slowEMA = ExpAverage(close, slowLength);
    def fastEMA_Short = ExpAverage(close, 5);
    def slowEMA_Short = ExpAverage(close, 12);

    def trend1250 = if fastEMA > slowEMA then 1 else -1; # 1 for Bullish, -1 for Bearish
    def trend512 = if fastEMA_Short > slowEMA_Short then 1 else -1; # 1 for Bullish, -1 for Bearish

    # Chop or Trend determination
    def chopOrTrend = if close > premarketHigh or close < premarketLow then 1 else 0;
    # 1 for Trending, 0 for Chop Range

    # Price Action Trend
    def priceActionTrend =
    if chopOrTrend and close > premarketHigh then 1
    else if chopOrTrend and close < premarketLow then -1
    else 0;
    # 1 for Bullish, -1 for Bearish, 0 for Chop Range

    # Convert numerical conditions to strings for AddLabel
    AddLabel(yes,
    “Price Action: ” +
    (if priceActionTrend == 1 then “Bullish” else if priceActionTrend == -1 then “Bearish” else “Chop Range”),
    if priceActionTrend == 1 then Color.GREEN else if priceActionTrend == -1 then Color.RED else Color.ORANGE);

    AddLabel(yes,
    “Ripster Clouds 12/50: ” + (if trend1250 == 1 then “Bullish” else “Bearish”),
    if trend1250 == 1 then Color.GREEN else Color.RED);

    AddLabel(yes,
    “Ripster Clouds 5/12: ” + (if trend512 == 1 then “Bullish” else “Bearish”),
    if trend512 == 1 then Color.GREEN else Color.RED);

    # Highlighting premarket levels
    plot premarketHighPlot = premarketHigh;
    premarketHighPlot.SetDefaultColor(Color.LIGHT_GREEN);
    premarketHighPlot.SetStyle(Curve.SHORT_DASH);

    plot premarketLowPlot = premarketLow;
    premarketLowPlot.SetDefaultColor(Color.LIGHT_RED);
    premarketLowPlot.SetStyle(Curve.SHORT_DASH);

    #242027

    C’est normal ce code n’est pas un code prorealtime.

    It’s normal this code is not a prorealtime code.

    #242028
    JS

    Hi,

    Although I don’t know the language, this error message probably means that you are using the wrong data type when declaring the times…

    “Double” indicates that you should use a “floating point” (decimal) number and not an integer for assigning “input endHour” and “input endMinute”…

    #242042

    I am using typescript which is used in ThinkorSwim platform. Although, I changed the variable into the floating number, still I caouldn’t resolve it.

     

    #242043

    @larouedegann

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thanks 🙂

     

    #242044
    JS

    Have you changed both the “datatype” and the input (variable) to “floating point”…?

    What is the input format for time in “typescript”?

    For example in ProRealTime it is a 24h format …

    #242047

    Thank you , I am able to fix the code and the code is running nicely..

    1 user thanked author for this post.
    avatar JS
Viewing 7 posts - 1 through 7 (of 7 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login