Description
Bot MACD opens positions at the close of bars, macd signal in favor of the trend.
Just turn on the robot on buy or sell sentiment
50% Automatic
If you turn the robot in favor of the trend, and the market goes against it, normally the robot will not open orders.
Símbolo EUR/GBP M30,
GBP/USD M30
Trend analysis required when turning on the robot.
Neste exemplo abaixo temos uma tendência de baixa, o teste de resistência acontece nas regiões marcadas com a seta, o ideal é ligar o robô logo após o preço ficar abaixo da média móvel de 50 períodos no setor de venda.
no momento o preço está em uma região de suporte o alvo é a mídia de 50 periudos para iniciar a venda do sentimento do
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 MACDMarketTimerV2 : Robot
{
[Parameter("Sentiment: Buy", DefaultValue = true)]
public bool Buy { get; set; }
[Parameter("Sentiment: Sell", DefaultValue = true)]
public bool Sell { get; set; }
[Parameter("MME Slow", Group = "MA", DefaultValue = 16)]
public int mmeSlow { get; set; }
[Parameter("MME Fast", Group = "MA", DefaultValue = 12)]
public int mmeFast { get; set; }
[Parameter("Source", Group = "RSI")]
public DataSeries Source { get; set; }
[Parameter("Periods", Group = "RSI", DefaultValue = 19)]
public int Periods { get; set; }
[Parameter("Start Hour", DefaultValue = 10.0)]
public double StartTime { get; set; }
[Parameter("Stop Hour", DefaultValue = 12.0)]
public double StopTime { get; set; }
[Parameter(" Period", Group="MACD",DefaultValue = 9)]
public int Period { get; set; }
[Parameter(" Long Cycle",Group="MACD", DefaultValue = 26)]
public int LongCycle { get; set; }
[Parameter(" Short Cycle",Group="MACD", 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 MovingAverage i_MA_slow;
private MovingAverage i_MA_fast;
private RelativeStrengthIndex rsi;
private DateTime _startTime;
private DateTime _stopTime;
private MacdCrossOver macd;
private double volumeInUnits;
protected override void OnStart()
{
i_MA_slow = Indicators.MovingAverage(Bars.ClosePrices, mmeSlow, MovingAverageType.Exponential);
i_MA_fast = Indicators.MovingAverage(Bars.ClosePrices, mmeFast, MovingAverageType.Exponential);
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
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 (rsi.Result.LastValue > 25 && rsi.Result.LastValue < 70)
{
if ((MACDLine > Signal & PrevMACDLine <PrevSignal & default==Sell) & (i_MA_fast.Result.LastValue > i_MA_slow.Result.LastValue))
{
ExecuteMarketOrder( TradeType.Buy ,SymbolName,volumeInUnits, "MACDMarketTimerV2,RSI,MACD",StopLoss,TakeProfit);
}
else if ( (MACDLine < Signal & PrevMACDLine >PrevSignal && default== Buy)&(i_MA_fast.Result.LastValue < i_MA_slow.Result.LastValue))
{
ExecuteMarketOrder( TradeType.Sell ,SymbolName,volumeInUnits, " MACDMarketTimerV2,RSI,MACD",StopLoss,TakeProfit);
}
}
}
}
protected override void OnStop()
{
}
}
}
carneiroads
Joined on 10.09.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: MACD Market Timer V2.algo
- Rating: 0
- Installs: 1656
Comments
Hello! Are your Start Hour and Stop Hour will follow by which type of category trades that we select like Indices/Forex/Gold/Oil/Equities or by which country server that you have been assigned for GMT?
Thank you.
I found this very useful but it has a problem of trading when the RSI is flat in the middle range. Is there a way to tell it NOT to execute for example RSI 45-55 range ?
Hi Carneiroads, excellent idea and good work of compiling a program that consist of using 3 indicators.
MACD crossover
RSI
MA or MME or Exponential Moving Average
Please correct me if above mentioned indicators are wrong.
I was wondering if possible that you can amend and compile below suggested flow chart idea by creating a new program will be highly appreciated.
MACD crossover as open trade.
RSI as close trade.
MME as close trade.
By the way, can please clarify below parameters meaning:
Start Hour / Stop Hour follow Server time = GMT 0 or timezone 0
MA MME= Exponential Moving Average (EMA)
Please correct me if wrong.
Hopefully and awaiting to hear any feedback from you.
Thank you.