0% found this document useful (0 votes)
11 views5 pages

EA

Uploaded by

Allan Haule
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

EA

Uploaded by

Allan Haule
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#property copyright "Your Name"

#property link "Your Website"

#property version "1.00"

#property strict

input int FastMAPeriod = 50; // Fast moving average period

input int SlowMAPeriod = 200; // Slow moving average period

input double StopLoss = 50; // Stop loss in points

input double TakeProfit = 100; // Take profit in points

input double LotSize = 0.01; // Lot size for trades

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

//---

return(INIT_SUCCEEDED);

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

//---

}
//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

double fastMA = iMA(Symbol(), 0, FastMAPeriod, 0, MODE_SMA,


PRICE_CLOSE, 0);

double slowMA = iMA(Symbol(), 0, SlowMAPeriod, 0, MODE_SMA,


PRICE_CLOSE, 0);

// Check for open trades and manage them

if(PositionSelect(_Symbol))

if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)

if(Bid <= PositionGetDouble(POSITION_PRICE_OPEN) - StopLoss * Point


||

Bid >= PositionGetDouble(POSITION_PRICE_OPEN) + TakeProfit *


Point)

CloseBuyPosition();

else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)

if(Ask >= PositionGetDouble(POSITION_PRICE_OPEN) + StopLoss * Point


||
Ask <= PositionGetDouble(POSITION_PRICE_OPEN) - TakeProfit *
Point)

CloseSellPosition();

// Open new trades based on MA crossover

if(fastMA > slowMA && !IsBuyPositionOpen())

OpenBuyPosition(LotSize);

else if(fastMA < slowMA && !IsSellPositionOpen())

OpenSellPosition(LotSize);

// Helper functions to check for open positions and open/close trades

bool IsBuyPositionOpen() {

// ... (Implementation to check for open buy positions)

bool IsSellPositionOpen() {

// ... (Implementation to check for open sell positions)

}
void OpenBuyPosition(double lotSize) {

// ... (Implementation to open a buy trade)

void OpenSellPosition(double lotSize) {

// ... (Implementation to open a sell trade)

void CloseBuyPosition() {

// ... (Implementation to close a buy trade)

void CloseSellPosition() {

// ... (Implementation to close a sell trade)

// ... (Previous code)

void OnTick()

// ... (Previous code)

// Price Action Integration (Example)

if (IsPinBar(0) && fastMA > slowMA)

OpenBuyPosition(LotSize);
}

else if (IsPinBar(0) && fastMA < slowMA)

OpenSellPosition(LotSize);

// Helper function to detect pin bars

bool IsPinBar(int shift)

// ... (Implementation to detect pin bars)

You might also like