Thank you again Raffty,
I am really looking for an EA rather than an indicator…Personally I know that sometimes if I have a skill at something and someone asks me to do it for them…the least I want is for them to take a shot at it first…so I have fried my brain and tried to write my first EA. (I knew very little of any programing 4 hours ago).
Goal of this EA:
Open an order AS SOON as there is a reversal of PSAR, and close any existing order as well.
I couldnt figure how to have the EA see a pure PSAR reversal, so I wrote it kinda like a SMA cross method, but rather than a Short SMA and a Long SMA I used a SMA that will just sit right in the middle of the candle sticks…then when the PSAR is below that = open buy, when PSAR is above that = open sell. (at least I think I did)
Problems, I dont even know if I am close, and when I try to pull it from my EA dropdown and pull it to a chart i get a message that says it cannot be loaded.
Would someone PLEASE look at this and tell me what I am doing wrong.
(sorry its so long of a post)
//±-----------------------------------------------------------------+
//| PSAR_Only.mq4 |
//| Michael |
//| N/A |
//±-----------------------------------------------------------------+
#property copyright “Michael”
#property link “N/A”
//---- input parameters
extern double Lots=1.0;
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1
if(line1<line2)current_direction = 2
if(current_direction != last_direction)
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
double sma, psar
//----
sma = iMA(NULL,0,1,0,MODE_SMA,PRICE_MEDIAN,0);
psar = iSAR(NULL,timeframe,0.02,0.2,0);
int isCrossed = Crossed (sma,psar);
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,NULL,12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
{
// should it be closed?
if(isCrossed == 2)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
// close position
return(0); // exit
}
// should it be closed?
if(isCrossed == 1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
// close position
return(0); // exit
}
return(0);
}
//±-----------------------------------------------------------------+