可以用if语句在任何位置控制他们,比如:
int a;
if (Buy condition is true) a=1;
else if (Sell condition is true) a=-1;
if (a==1){
//---------
//---------
}
else if (a==-1){
//---------
//---------
}
我的英语很不好 , 祝你好运!
Hi Guys,
This is my first Post!!!
I'm looking for a function to flip the Portfolio position from +1 to -1 and -1 to +1 immediately
i.e, when sell signal is given, the command will close the buy position but straight away change the position to -1
Regards,
ShinjiOno
What you have described is not a function, it is a whole bunch of code. Ok you could wrap the whole bunch of code up into a function called ShinjiOnoFunction(), unique to you, but then who is supposed to write that?
So, let's suppose you want to write your own EA to perform this function. You could write something like this ...
#define NOPOSITION 2324263 #define LONGPOSITION 2324264 #define SHORTPOSITION 2324265 int start(){ int state= GetCurrentPosition(); bool couldGoShort= SellSignal(); // is there a sell signal? bool couldGoLong = BuySignal(); // is there a buy signal? switch(state){ case NOPOSITION: if( couldGoShort ){ GoSHORT(); // open a SHORT position return(0); } if( couldGoLong ){ GoLONG(); // open a LONG position return(0); } break; case LONGPOSITION: if( couldGoShort ){ ClosePosition(); // close any open position related to this trading system and this chart GoSHORT(); return(0); } break; case SHORTPOSITION: if( couldGoLong ){ ClosePosition(); GoLONG(); return(0); } break; default: Print("WTF? We shouldn't be here"); break; } }
Where there are lots of smaller functions to be written that are more approachable than having to do everything all at once.
But frankly I don't think my code above is going to be much use to you, because even though it is very simple, it may still be too much for a total beginner. So, where to start? Well the book is a good place to start.
Since you don't even say if you have any understanding of C, or another programming language, it is hard to know what else to say.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Guys,
This is my first Post!!!
I'm looking for a function to flip the Portfolio position from +1 to -1 and -1 to +1 immediately
i.e, when sell signal is given, the command will close the buy position but straight away change the position to -1
Regards,
ShinjiOno