Sma Tenken Sell

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MetaTrader 4 (MT4) platformasida 200 SMA (Simple Moving Average) va

Tenkan-sen chizig'i asosida sell savdo signaliga asoslangan avtomat robot (Expert
Advisor) yaratish uchun MQL4 dasturlash tilidan foydalanish kerak. Quyidagi
kodni o'z ichiga olgan faylni yaratib, MT4 platformasiga yuklashingiz mumkin:

cpp
Копировать код
//+------------------------------------------------------------------+
//| SellRobot.mq4|
//| Copyright 2024, MetaQuotes Software Corp. |
//| https://www.metaquotes.net|
//+------------------------------------------------------------------+
#property strict

// Input parameters
input double Lots = 0.1; // Lot size
input int Slippage = 3; // Maximum slippage
input double StopLoss = 50; // Stop loss in points
input double TakeProfit = 100; // Take profit in points

// Indicator parameters
input int SMA_Period = 200; // Period for SMA
input int TenkanSen_Period = 9; // Period for Tenkan-sen

double SMA[], TenkanSen[];

int OnInit()
{
//--- SMA initialization
SetIndexBuffer(0, SMA);
ArraySetAsSeries(SMA, true);
IndicatorBuffers(1);
IndicatorShortName("SMA 200");

//--- Tenkan-sen initialization


SetIndexBuffer(1, TenkanSen);
ArraySetAsSeries(TenkanSen, true);
IndicatorBuffers(2);
IndicatorShortName("Tenkan-sen 9");

return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,


const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- SMA calculation
for (int i = 0; i < rates_total; i++)
{
SMA[i] = iMA(NULL, 0, SMA_Period, 0, MODE_SMA,
PRICE_CLOSE, i);
}

//--- Tenkan-sen calculation


for (int i = 0; i < rates_total; i++)
{
double maxHigh = high[iHighest(NULL, 0, MODE_HIGH,
TenkanSen_Period, i)];
double minLow = low[iLowest(NULL, 0, MODE_LOW,
TenkanSen_Period, i)];
TenkanSen[i] = (maxHigh + minLow) / 2;
}

return(rates_total);
}

void OnTick()
{
// Check if we have enough bars
if (Bars < SMA_Period || Bars < TenkanSen_Period)
return;

// Get the latest values


double currentSMA = SMA[0];
double currentTenkanSen = TenkanSen[0];
double previousTenkanSen = TenkanSen[1];

// Check if Tenkan-sen crosses below SMA 200


if (previousTenkanSen > currentSMA && currentTenkanSen <
currentSMA)
{
// Open sell order
int ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,
Bid + StopLoss * Point,
Bid - TakeProfit * Point,
"Sell order by Tenkan-sen and SMA 200",
0, 0, Red);
if (ticket < 0)
Print("Error opening sell order: ", ErrorDescription(GetLastError()));
}
}

string ErrorDescription(int error_code)


{
switch (error_code)
{
case 0: return("No error returned.");
case 1: return("No error returned, but the result is unknown.");
case 2: return("Common error.");
case 3: return("Invalid trade parameters.");
case 4: return("Trade server is busy.");
case 5: return("Old version of the client terminal.");
case 6: return("No connection with trade server.");
case 7: return("Not enough rights.");
case 8: return("Too frequent requests.");
case 9: return("Malfunctional trade operation.");
case 64: return("Account disabled.");
case 65: return("Invalid account.");
case 128: return("Trade timeout.");
case 129: return("Invalid price.");
case 130: return("Invalid stops.");
case 131: return("Invalid trade volume.");
case 132: return("Market closed.");
case 133: return("Trade is disabled.");
case 134: return("Not enough money.");
case 135: return("Price changed.");
case 136: return("Off quotes.");
case 137: return("Broker is busy.");
case 138: return("Requote.");
case 139: return("Order is locked.");
case 140: return("Long positions only allowed.");
case 141: return("Too many requests.");
case 145: return("Modification denied because order is too close to
market.");
case 146: return("Trade context is busy.");
case 147: return("Expirations are denied by broker.");
case 148: return("The amount of opened and pending orders has reached
the limit set by the broker.");
case 149: return("Attempt to modify the order resulted in a change of the
price.");
case 150: return("Attempt to open an order resulted in a change of the
price.");
default: return("Unknown error.");
}
}
//+------------------------------------------------------------------+
Yuqoridagi kod MT4 uchun Expert Advisor (EA) yaratadi, u Tenkan-sen
chizig'i 200 SMA chizig'idan pastga o'tganda avtomatik sell buyurtma ochadi. EA
ni yaratish uchun quyidagi amallarni bajaring:

MetaTrader 4 platformasini oching.


"File" menyusidan "Open Data Folder" ni tanlang.
"MQL4" papkasini oching va "Experts" papkasiga o'ting.
Yangi fayl yaratib, unga SellRobot.mq4 nomini bering.
Yuqoridagi kodni ushbu faylga joylashtiring va saqlang.
MT4 platformasiga qaytib, "Navigator" oynasidan "Experts" bo'limini
yangilang.
"SellRobot" ni topib, chartga qo'shing.
Shundan so'ng, robot Tenkan-sen chizig'i 200 SMA chizig'idan pastga
o'tganda sell savdolarini avtomatik ravishda ochadi.

Handling multiple papers?

Our AI sidebar -- Sider assists you skim through papers 10X faster using its
10+ one-click research tools like deep reader, advanced search, ChatPDF, and
context selection.
Get ready for a smarter academic experience!

You might also like