Announcement

Collapse
No announcement yet.

ma buy/sell signals

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ma buy/sell signals

    can someone please code a buy/sell (green/red arrows maybe) into this code? Thank you

    function preMain()
    {
    setPriceStudy(true);

    setStudyTitle("Simple Futures MA");

    setCursorLabelName("FastMA", 0);
    setCursorLabelName("SlowMA", 1);
    setCursorLabelName("Filter", 2);

    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.green, 2);
    }
    function main(Price, FastAvg, SlowAvg, AvgFltr)
    {
    if (Price == null) Price = "Close";
    if (FastAvg == null) FastAvg = 9;
    if (SlowAvg == null) SlowAvg = 50;
    if (AvgFltr == null) AvgFltr = 80;
    var FastMA = 0.0;//Average(Price, FastAvg);
    var SlowMA = 0.0;//Average(Price, SlowAvg);
    var Filter = 0.0;//Average(Price, AvgFltr);
    var MaxLen = 0.0;
    if (MaxLen <= FastAvg) MaxLen = FastAvg;
    if (MaxLen <= SlowAvg) MaxLen = SlowAvg;
    if (MaxLen <= AvgFltr) MaxLen = AvgFltr;
    var vPrice = getValue(Price, 0, -MaxLen);
    var i = 0;
    for (i = 0; i < MaxLen; i++)
    {
    if (i < FastAvg) FastMA += vPrice[i];
    if (i < SlowAvg) SlowMA += vPrice[i];
    if (i < AvgFltr) Filter += vPrice[i];
    }
    FastMA /= FastAvg;
    SlowMA /= SlowAvg;
    Filter /= AvgFltr;
    return new Array(FastMA, SlowMA, Filter);
    }

  • #2
    I can do this for you....

    I can help you accomplish this, but under which conditions do you want the arrows drawn??

    What would constitute a buy signal or a sell signal??

    Any further input would be greatly appreciated.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      ma buy/sell

      Sorry Brad,
      A green arrow when the 9 crosses the 50 up and a red arrow when the 9 crosses the 50 down would be fine. Also if you wouldn't mind, how to thicken the lines? They are very thin on the charts.
      Thanks for your help
      piratelady

      Comment


      • #4
        Code with Arrows...

        Here you go...

        PHP Code:
        var TrendDirection 0;

        function 
        preMain()
        {
          
        setPriceStudy(true);
          
        setStudyTitle("Simple Futures MA");
          
        setCursorLabelName("FastMA"0);
          
        setCursorLabelName("SlowMA"1);
          
        setCursorLabelName("Filter"2);

          
        setDefaultBarFgColor(Color.blue0);
          
        setDefaultBarFgColor(Color.red1); 
          
        setDefaultBarFgColor(Color.green2);
        }

        function 
        main(PriceFastAvgSlowAvgAvgFltr)
        {
         if (
        Price == nullPrice "Close";
         if (
        FastAvg == nullFastAvg 9;
         if (
        SlowAvg == nullSlowAvg 50;
         if (
        AvgFltr == nullAvgFltr 80;
         var 
        FastMA 0.0;//Average(Price, FastAvg);
         
        var SlowMA 0.0;//Average(Price, SlowAvg);
         
        var Filter 0.0;//Average(Price, AvgFltr);
         
        var MaxLen 0.0;
         if (
        MaxLen <= FastAvgMaxLen FastAvg;
         if (
        MaxLen <= SlowAvgMaxLen SlowAvg;
         if (
        MaxLen <= AvgFltrMaxLen AvgFltr;
         var 
        vPrice getValue(Price0, -MaxLen);
         var 
        0;
         for (
        0MaxLeni++)
         {
            if (
        FastAvgFastMA += vPrice[i];
            if (
        SlowAvgSlowMA += vPrice[i];
            if (
        AvgFltrFilter += vPrice[i];
         }
         
        FastMA /= FastAvg;
         
        SlowMA /= SlowAvg;
         
        Filter /= AvgFltr;

         if ((
        FastMA SlowMA) && (TrendDirection <= 0)) {
            
        drawShapeRelative(0,low(),Shape.UPARROW,null,Color.green,Shape.ONTOPgetValue("rawtime",0)+"BUY");
           
        TrendDirection 1;  //  Bullish
         
        }
         if ((
        FastMA SlowMA) && (TrendDirection >= 0)) {
            
        drawShapeRelative(0,high(),Shape.DOWNARROW,null,Color.red,Shape.ONTOPgetValue("rawtime",0)+"SELL");
           
        TrendDirection = -1;  //  Bullish
         
        }

         return new Array(
        FastMASlowMAFilter);

        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          ma buy/sell

          thanks alot brad! That was fast!
          piratelady

          Comment


          • #6
            ma buy/sell

            I must be a dork brad but I can't get it to work. Here is the link to the .efs can ya maybe put the signals in and post it where I can download it straight into the formulas?
            Thanks
            piratelady


            Comment

            Working...
            X