Let AI do its thing
https://openai.com/
I don't know how to code but with chat gpt, you just need specific inquiries and boom, MT5 and NT8 codes for MA crossover just like that
The cool thing is that it also explains the code generated. So you can technically learn how to code in segments with AI walking you through each code.
It's not perfect, I had to do multiple inquiries with the right words to get the majority of the code down. But sure is interesting
https://openai.com/
I don't know how to code but with chat gpt, you just need specific inquiries and boom, MT5 and NT8 codes for MA crossover just like that
Code:
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\TradeTransInfo.mqh>
#define MA_PERIOD1 5
#define MA_PERIOD2 15
int handle;
double ma1, ma2;
void OnStart()
{
// Set up the moving averages
handle = iMA(NULL, 0, MA_PERIOD1, 0, MODE_SMA, PRICE_CLOSE, 0);
if (handle == INVALID_HANDLE)
{
Print("Failed to set up moving average 1");
return;
}
handle = iMA(NULL, 0, MA_PERIOD2, 0, MODE_SMA, PRICE_CLOSE, 0);
if (handle == INVALID_HANDLE)
{
Print("Failed to set up moving average 2");
return;
}
}
void OnTick()
{
// Get the current values of the moving averages
ma1 = iMA(NULL, 0, MA_PERIOD1, 0, MODE_SMA, PRICE_CLOSE, 0);
ma2 = iMA(NULL, 0, MA_PERIOD2, 0, MODE_SMA, PRICE_CLOSE, 0);
// Check if the moving averages have crossed
if (ma1 > ma2)
{
// Moving average 1 is above moving average 2, so we will enter a long position
if (!PositionSelect(NULL))
{
// No open position, so we will open a new one
TradeRecord tr;
tr.Comment = "MA Crossover Long";
if (OrderSend(Symbol(), OP_BUY, 1.0, Ask, 3, 0, 0, tr.Comment, 0, 0, CLR_NONE))
{
Print("Order sent successfully");
}
else
{
Print("Failed to send order");
}
}
else
{
// There is already an open position, so we will do nothing
}
}
else if (ma1 < ma2)
{
// Moving average 1 is below moving average 2, so we will enter a short position
if (!PositionSelect(NULL))
{
// No open position, so we will open a new one
TradeRecord tr;
tr.Comment = "MA Crossover Short";
if (OrderSend(Symbol(), OP_SELL, 1.0, Bid, 3, 0, 0, tr.Comment, 0, 0, CLR_NONE))
{
Print("Order sent successfully");
}
else
{
Print("Failed to send order");
}
}
else
{
// There is already an open position, so we will do nothing
}
}
else
{
// Moving averages are equal, so we will do nothing
}
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Indicator;
using NinjaTrader.NinjaScript;
using NinjaTrader.Strategy;
namespace MyNamespace
{
public class MyAlgorithm : Strategy
{
private SMA sma1;
private SMA sma2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "A moving average crossover strategy";
Name = "MyAlgorithm";
// Set the default values for the SMA indicators
sma1 = SMA(Close, 5);
sma2 = SMA(Close, 15);
}
}
protected override void OnBarUpdate()
{
// Check if the moving averages have crossed
if (sma1[0] > sma2[0])
{
// Moving average 1 is above moving average 2, so we will enter a long position
if (Position.MarketPosition == MarketPosition.Flat)
{
EnterLong(1, "MA Crossover Long");
}
}
else if (sma1[0] < sma2[0])
{
// Moving average 1 is below moving average 2, so we will enter a short position
if (Position.MarketPosition == MarketPosition.Flat)
{
EnterShort(1, "MA Crossover Short");
}
}
else
{
// Moving averages are equal, so we will do nothing
}
}
}
}
The cool thing is that it also explains the code generated. So you can technically learn how to code in segments with AI walking you through each code.
It's not perfect, I had to do multiple inquiries with the right words to get the majority of the code down. But sure is interesting