Multi-time-Frame Indicators with Multicharts?

Discussion in 'Automated Trading' started by yosuji198, Apr 3, 2023.

  1. yosuji198

    yosuji198

    Hi Community,

    I'm trying to create a code that has a simple MACD on 1 minute and 3 minute timeframe simultaneously. Problem is it doesn't work. In my Multicharts I have loaded both the 1 minute and the 3 minute charts into the same Window. But for the Indicator when I go into its properties and select 'base study on' I can only choose either the 1 minute or the 3 minute. Which means the only way to see a true multi-time frame indicator is to have a MACD indicator on the 1 minute and a separate MACD indicator on the 3 minute overlapping each other in the same Subchart.

    But that won't work. I need one code that can generate trades based on the interaction of the 1 minute and 3 minute indicators on the same chart. Am I missing something?
    In Tradingview it's easy you can just use the code "
    macd_3 = request.security(syminfo.tickerid, "3", macd). But i'm struggling with how to do it for Multicharts.

    EasyLanguage Code is below:
    Inputs: FastLength(12), SlowLength(26), SignalLength(9);

    Variables: FastMA(0), SlowMA(0), MACD(0), Signal(0), MACD_3(0), Signal_3(0),

    FastMA = XAverage(Close, FastLength);
    SlowMA = XAverage(Close, SlowLength);
    MACD = FastMA - SlowMA;
    Signal = XAverage(MACD, SignalLength);

    Plot1(MACD, "MACD");
    Plot2(Signal, "Signal");

    // Calculate MACD and signal for 3 min timeframe
    MACD_3 = MACD of Data2;
    Signal_3 = XAverage(MACD of Data2, SignalLength);

    Plot3(MACD_3, "MACD 3 min");
    Plot4(Signal_3, "Signal 3 min");
     
  2. VSTscalper

    VSTscalper

    Use a Semi-Colon - at the End of the Variables.

    Is:

    Variables: FastMA(0), SlowMA(0), MACD(0), Signal(0),
    MACD_3(0), Signal_3(0),

    Should be:

    Variables: FastMA(0), SlowMA(0), MACD(0), Signal(0),
    MACD_3(0), Signal_3(0);

    Just copy from "Inputs to the End of Plot4"
    It does Compile - let me know if there is a problem.


    By the way - it is PowerLanguage in Multicharts - not EasyLanguage.

    Correct:

    Inputs: FastLength(12),
    SlowLength(26),
    SignalLength(9);

    Variables: FastMA(0),
    SlowMA(0),
    MACD(0),
    Signal(0),
    MACD_3(0),
    Signal_3(0);

    FastMA = XAverage(Close, FastLength);
    SlowMA = XAverage(Close, SlowLength);
    MACD = FastMA - SlowMA;
    Signal = XAverage(MACD, SignalLength);

    Plot1(MACD, "MACD");
    Plot2(Signal, "Signal");

    // Calculate MACD and signal for 3 min timeframe
    MACD_3 = MACD of Data2;
    Signal_3 = XAverage(MACD of Data2, SignalLength);

    Plot3(MACD_3, "MACD 3 min");
    Plot4(Signal_3, "Signal 3 min");
     
    Last edited: Apr 3, 2023
  3. yosuji198

    yosuji198

    Your code does compile. But it's still not showing multi time frame. As shown below the MACD and Signal have the same values as the 3 minute MACD and Signal. Is there a way to apply the indicator such that it shows both the 1 and 3 minute? Thanks!
    upload_2023-4-3_20-38-40.png
     
  4. MarkBrown

    MarkBrown

    try replace close with ((c data1+c data2)/2 )
     
  5. VSTscalper

    VSTscalper

    It is NOT my Code - it is YOUR Code - I just changed the Comma to a Semicolon. I haven't tried it on a chart - just don't have time.

    I don't use Indicators anymore.

    Good luck
     
  6. yosuji198

    yosuji198

    Thanks for the suggestion but it didn't work. I tried the below and again 1 minute and 3 minute plots have the same number
    FastMA_3 = XAverage(((c data1+ c data2)/2), FastLength);
    SlowMA_3 = XAverage(((c data1+ c data2)/2), SlowLength);
     
  7. yosuji198

    yosuji198

    Haha. Thanks. It compiled fine before but i'm just trying to figure out the multi time frame thing. If you have an extra minute again please see if it could work on your charts
     
  8. VSTscalper

    VSTscalper

    It would probably make me Sick - just adding an Indicator on my Chart. I do have an old setup - with Green and Red Dots - based on a One Tick Range Bar - and once in awhile - I will still trade that Setup. I use my Algos for Signals - and I only look at the Current Bar - to Enter a trade.

    I have a tread on ET - you will see how I trade. Just a Simple Signal to Enter a trade. At my age now - getting near Fossil Age - just looking at Indicators - could cause anxiety - and cause me to Fart - or Worse - so I need to be careful.
     
  9. yosuji198

    yosuji198

    No worries all. I figured it out on my own using some old youtube videos. Correct code is below. To make it work you have to have a chart representing Data1 and another chart representing Data2. Then the following code works:

    upload_2023-4-3_21-16-22.png

    Inputs: FastLength(12),
    SlowLength(26),
    SignalLength(9);

    Variables: FastMA(0),
    SlowMA(0),
    MACD(0),
    Signal(0),
    MACD_3(0, data2),
    Signal_3(0, data2),
    FastMa_3(0, data2),
    SlowMa_3(0, data2);

    FastMA = XAverage(Close, FastLength);
    SlowMA = XAverage(Close, SlowLength);
    MACD = FastMA - SlowMA;
    Signal = XAverage(MACD, SignalLength);

    FastMA_3 = XAverage(close data2, FastLength);
    SlowMA_3 = XAverage(close data2, SlowLength);
    MACD_3 = FastMA_3 - SlowMA_3;
    Signal_3 = XAverage(MACD_3, SignalLength);


    Plot1(MACD, "MACD");
    Plot2(Signal, "Signal");

    // Calculate MACD and signal for 3 min timeframe
    //MACD_3 = MACD of Data2;
    //Signal_3 = XAverage(MACD of Data2, SignalLength);

    Plot3(MACD_3, "MACD 3 min");
    Plot4(Signal_3, "Signal 3 min");
     
    Rnstwy and MarkBrown like this.
  10. VSTscalper

    VSTscalper

    I have Algos - that use several Data Series.

    Just a recommendation - to keep it Clean - in case at some point you want to look back at your Code - I would suggest for the FastMA and SlowMA - instead of just Close - use Close of Data1. Also - with Data 2 - you have some with a small first letter - data2 and some with capital first letter - Data2 - just try to be consistent. While you don't need it - I always use the word "of" - between Close and Data_. Same thing for Signal - Caps or not Caps. Again - just a recommendation. It is all about being Consistent in your Code.
     
    #10     Apr 3, 2023