MACD Market Timer free

by carneiroads in category Trend at 18/09/2022
Description

 Robot with MACD signal trend. M30 -H4 GBPUSD. if the market changes the primary trend to high, change the code indicated. I'm working to adjust this function.

 

 

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class MACDMarketTimer : Robot
    {

       
        [Parameter("Start Hour", DefaultValue = 10.0)]
        public double StartTime { get; set; }

        [Parameter("Stop Hour", DefaultValue = 12.0)]
        public double StopTime { get; set; }
                     
        [Parameter("Period", DefaultValue = 9)]
        public int Period { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }
   
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }
                      
        [Parameter("Stop Loss ", DefaultValue = 100)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 100)]
        public int TakeProfit { get; set; }
      
                   
        private DateTime _startTime;
        private DateTime _stopTime;               
        private MacdCrossOver macd;
        private double volumeInUnits;
                
        protected override void OnStart()
        
        {
            macd=Indicators.MacdCrossOver(LongCycle, ShortCycle, Period);
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
             {
            
            _startTime = Server.Time.Date.AddHours(StartTime);
        
            _stopTime = Server.Time.Date.AddHours(StopTime);

            Print("Start Time {0},", _startTime);
            Print("Stop Time {0},", _stopTime);
            
             } 
            
        }
                       
        protected override void OnBar()
        {
              
        var MACDLine  = macd.MACD.Last(1);
        var PrevMACDLine = macd.MACD.Last(2);
        var Signal  = macd.Signal.Last(1);
        var PrevSignal= macd.Signal.Last(2);
        
        if (Trade.IsExecuting) return;

            var currentHours = Server.Time.TimeOfDay.TotalHours;
            bool tradeTime = StartTime < StopTime
                ? currentHours > StartTime && currentHours < StopTime
                : currentHours < StopTime || currentHours > StartTime;

            if (!tradeTime)
                return;
     

                
       {
             if    (MACDLine >Signal & PrevMACDLine < PrevSignal )
                   
         {           //  The code is only for sale change to buy if you want both, or change according to the market trend
                     ExecuteMarketOrder( TradeType.Sell  ,SymbolName,volumeInUnits, "MACDMarketTimer",StopLoss,TakeProfit);
                  }                           //.Buy
         
                     else if  (MACDLine < Signal & PrevMACDLine > PrevSignal )
                                         
                  {
                   
                     ExecuteMarketOrder( TradeType.Sell ,SymbolName,volumeInUnits, " MACDMarketTimer",StopLoss,TakeProfit);
                                                   //Buy
                  }
            }
         
       }     
                   
             protected override void OnStop()
        {
          
        }
    }
}

Comments

deleonandrews4942917 - September 21, 2022 @ 18:42

oh the numbers are headache. Really diggy will not let you down. Try and experience

0