Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

Intégrer un code trailling stop, Spoutnik V1.08 by Furynick

  • Jerome

    Bonjour,

    Je souhaiterai intégrer le code suivant :) :

    http://www.autoforex.fr/trailing-stop-et-trailing-profit/

    dans le script de spoutnik :

    Code
    //+------------------------------------------------------------------+ //| S P O U T N I K v1.08 by Furynick //| Free for all the forexagone.com members //| Gratuit pour les membres de forexagone.com //+------------------------------------------------------------------+ //| Last version is Spoutnik v1.08 by Furynick, first week of May 2011. //+------------------------------------------------------------------+ //| v1.08 by Furynick //| - Different sounds added when a position is opened and closed. //| //| v1.07 by Furax: //| - Modified Angle Alpha to <-25 and >25 //| ( Increase the opportunitie to open a new trade. ) //| - Modified "TakeProfit" name to be more clear for the users. //| - Modified "NBPositions" name to be more clear for the users. //| ( Number of the positions allowed for the pair AND for all the other pairs. ) //| - Modified the value of T/P, S/L, DecreaseFactor. //| - Modified "comments". The number of the version appears now correctly. //| - Created the data "Security" to protect the account pair by pair. //| ( Every pair can have his own value for "Security" in EUR, USD and more. ) //[ ( The new little formula created is : Security = Equity - Margin ) //| ( In fact, "Security" is the "Available Margin". ) //| ( By default, the setting is 500€, 500$ or another currency. ) //| //| v1.06 by Furynick: //| Created S/L by Furynick. Thank you so much. //| //| v1.05 by Furax: //| Added "TotalNBPositionsMaxi" to increase the money magement. //| //| v1.04 by Furax: //| - Modified Angle Alpha to -85 to -85 by Furax //+------------------------------------------------------------------+ //| Copyright © 2005, MetaQuotes Software Corp. //| http://www.metaquotes.net //+------------------------------------------------------------------+ #property copyright "Copyright © 2011. Furax for forexagone.com" #property link "http://www.forexagone.com/" #define MAGICMA 20050610 extern double Lots = 0.1; // was 1.2 extern double TotalNBPositionsMaxi = 30; // added line by Furax for v1.05 extern double Security = 500; // Added a security with free margin by Furax for v1.07 extern double MaximumRisk = 0.036; // was 0.036 extern double DecreaseFactor = -12; // was -100 extern double TakeProfit = 100; // was 15 extern int StopLoss = 20; // Added by Furinick for v1.06 extern double MAPeriod = 1.0; double spread = 1.5; bool openSound = false; bool closeSound = false; // was 1.5 //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double Laguerre; double Alpha; double MA, MAprevious; int cnt, ticket, total; // was int cnt, ticket, total; Laguerre = 0; //iCustom(NULL, 0, "Laguerre", 0, 0); Alpha = iCCI(NULL, 0, 14, PRICE_CLOSE, 0); MA = iMA(NULL,0,MAPeriod, 0, MODE_EMA, PRICE_MEDIAN, 0); MAprevious = iMA(NULL, 0, MAPeriod, 0, MODE_EMA, PRICE_MEDIAN, 1); // ***************************************************************** Number of positions in the air total = OrdersTotal(); if(total < TotalNBPositionsMaxi) { // was if(total < 3) Number of positions // ****************************************************************************************************** { // no opened orders identified if(AccountFreeMargin() < ((Security *10)*Lots)) { // was if(AccountFreeMargin() < (1000*Lots)) // Security to verified... { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } // check for long position (BUY) possibility if((Laguerre == 0) && (MA > MAprevious) && (Alpha < -25)) { //+-- && Juice>JuiceLevel) // was if((Laguerre == 0) && (MA > MAprevious) && (Alpha < -5)) //+-- && Juice>JuiceLevel)// <-105 { ticket = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, 3, Ask - StopLoss * Point * MathPow(10, Digits % 2), 0, "Buy-Spoutnik v1.08", 16384, 0, Green); if (GetLastError() == 0) openSound=true; } // check for short position (SELL) possibility if((Laguerre == 0) && (MA < MAprevious) && (Alpha > 25)) { //+-- && Juice>JuiceLevel) // was if((Laguerre == 0) && (MA < MAprevious) && (Alpha > 5)) //+-- && Juice>JuiceLevel)// > 105 { ticket = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, 3, Bid + StopLoss * Point * MathPow(10, Digits % 2), 0, "Sell-Spoutnik v1.08", 16384, 0, Red); if (GetLastError() == 0) openSound=true; } } // it is important to enter the market correctly, // but it is more important to exit it correctly... for (cnt = 0; cnt < total; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType() <= OP_SELL && // check for opened position OrderSymbol() == Symbol()) { // check for symbol { if(OrderType() == OP_BUY) { // long position is opened { // should it be closed? if(Laguerre > 1) {// was > 0 { if (OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet)) closeSound=true; // close position return(0); // exit } // check for stop if(TakeProfit > 1) { // was > 0 { if(Bid - OrderOpenPrice() > Point*TakeProfit) { if (OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet)) closeSound=true; // close position return(0); } } } else { // go to short position { // should it be closed? if(Laguerre > 0) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position return(0); // exit } // check for TakeProfit if(TakeProfit > 0) { if(OrderOpenPrice() - Ask > Point*TakeProfit) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position return(0); } } } } } if (openSound) { PlaySound("ok.wav"); openSound = false; } if (closeSound) { PlaySound("expert.wav"); closeSound = false; } return(0); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double LotsOptimized() { double lot = Lots; // was double lot = Lots; int orders = HistoryTotal(); // history orders total int losses = 2; // number of losses orders without a break was 0 then 3 //---- select lot size lot = NormalizeDouble(AccountFreeMargin()*MaximumRisk / 500, 1); //---- calcuulate number of losses orders without a break if(DecreaseFactor > 1) { // was if(DecreaseFactor > 0) { for (int i = orders - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) { Print("Error in history!"); break; } //---- if(OrderSymbol() != Symbol() || OrderType() > OP_SELL) continue; //---- if(OrderProfit() > 0) break; //---- if(OrderProfit() < 0) losses++; } if(losses > 1) lot = NormalizeDouble(lot - lot*losses / DecreaseFactor,1); } //---- return lot size if(lot <0.1)// was if(lot < 0.1) lot = 0.1; // was lot = 0.1; return(lot); } //+------------------------------------------------------------------+ // the end.
    Modifié le 2012-10-15 17:53:44 par AliX
  • Jerome

    Je sais que la demande est exagéré surtout en comparaison de ce que j'ai pu apporté au forum c'est a dire rien du tout ^^
    en échange je promet quelquechose qui comblera toute personne en recherche ésotérique, une méthode de captation énergétique qui copie le système des plantes, fleurs , arbres !
    si j'en dis plus je balance le secret :)
  • Jerome

    le système est une photosynthèse pour homme ....
  • sidfrag

    t'es serieux la?..
  • Jerome

    yep
  • Jerome

    c'est si dur que ça ?
    un indice svp .
  • jérôme (invité)

    sniff sniff
  • Baloche

    Salut,

    Tu ajoutes ce code au début de l'EA dans la déclaration des variables :
    Code
    extern bool useTrailingStop = true; extern int trailingTrigger = 10; extern int trailingTP = 13; extern int trailingSL = 13;

    Celui-ci juste au début de l'EA, après "int start() {" :
    Code
    if(useTrailingStop == true && OrdersTotal() > 0){ trailing(); }

    Et enfin celui-ci tout à la fin après le "}" de cloture :
    Code
    void trailing() { for (int i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS)) { if (MagicNumber == OrderMagicNumber()) { if (OrderType() == OP_BUY) if (OrderTakeProfit() – Bid <= trailingTrigger * Point && Bid < OrderTakeProfit()) OrderModify(OrderTicket(), 0, Bid – trailingSL * Point, OrderTakeProfit() + trailingTP * Point, 0, White); if (OrderType() == OP_SELL) if (Ask – OrderTakeProfit() <= trailingTrigger * Point && Ask > OrderTakeProfit()) OrderModify(OrderTicket(), 0, Ask + trailingSL * Point, OrderTakeProfit() – trailingTP * Point, 0, White); } } } }
  • jagaur1637

    superbe
  • Jerome

    ça ne marche pas pour moi*..........