for ($i = 1; $i <= 1000; $i++){ echo "Be Happy"; }

Blog

Buscar por Categorias o Tags


Cómo crear un Expert Advisor metatrader 5

Código paso a paso para crear un expert advisor que nos ayude a administrar las posiciones que vamos abriendo manualmente.

En mi canal de youtube hay un video del paso a paso:

  1. Crear un nuevo proyecto.

  2. Crear variables:
    • globalTrailing
    • globaltrailingStop
    • globalStopLoss
    • globalSpread
  3. Copiar codigo:
//+------------------------------------------------------------------+
//|                                                      vikingo.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>
CTrade trade;

//--- input parameters
input int globalTrailing;
input int globalTrailingStop;
input int globalStopLoss;
input int globalSpread;

bool     test = false;
bool     globalPositionInit = true;
long     globalPositionTrailing;
double   globalTickValue;
ulong    globalTicket;
string   globalSymbol;
string   globalPositionSymbol;
long     globalPositionType;
long     globalPositionOpen;
long     globalPositionStop;
double   globalGross;
long     globalPrice;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   globalSymbol = Symbol();
   globalTickValue = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE);
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(test)
     {
      ulong ticket = trade.Buy(0.01, Symbol(), SymbolInfoDouble(Symbol(), SYMBOL_ASK));
      //ulong ticket = trade.Sell(0.01, Symbol(), SymbolInfoDouble(Symbol(), SYMBOL_BID));
      test = false;
     }
   int total = PositionsTotal();
   if(total > 0)
     {
      globalTicket = PositionGetTicket(0);
      globalGross = PositionGetDouble(POSITION_PROFIT);
      globalPositionSymbol = PositionGetString(POSITION_SYMBOL);
      globalPositionOpen = priceConvert(PositionGetDouble(POSITION_PRICE_OPEN));
      globalPositionType = PositionGetInteger(POSITION_TYPE);

      if(globalPositionType == POSITION_TYPE_SELL)
        {
         globalPrice = priceConvert(SymbolInfoDouble(globalPositionSymbol, SYMBOL_ASK));
         if(globalPositionInit)
           {
            globalPositionStop = globalPositionOpen + globalStopLoss;
            globalPositionTrailing = globalPositionOpen - globalTrailing - globalSpread;
            globalPositionInit = false;
           }

         if(globalPrice <= globalPositionTrailing && globalGross > 0)
           {
            globalPositionTrailing = globalPrice - globalTrailing;
            globalPositionStop = globalPrice + globalTrailingStop;
           }

         if(globalPrice >= globalPositionStop)
           {
            bool result = trade.PositionClose(globalTicket);
            if(result)
              {
               resetInit();
              }
            else
              {
               Print("No se pudo cerrar la posición de venta");
              }
           }
        }
      else
         if(globalPositionType == POSITION_TYPE_BUY)
           {
            globalPrice = priceConvert(SymbolInfoDouble(globalPositionSymbol, SYMBOL_BID));
            if(globalPositionInit)
              {
               globalPositionStop = globalPositionOpen - globalStopLoss;
               globalPositionTrailing = globalPositionOpen + globalTrailing + globalSpread;
               globalPositionInit = false;
              }

            if(globalPrice >= globalPositionTrailing && globalGross > 0)
              {
               globalPositionTrailing = globalPrice + globalTrailing;
               globalPositionStop = globalPrice - globalTrailingStop;
              }

            if(globalPrice <= globalPositionStop)
              {
               bool result = trade.PositionClose(globalTicket);
               if(result)
                 {
                  resetInit();
                 }
               else
                 {
                  Print("No se pudo cerrar la posición de compra");
                 }
              }
           }
      Print("Ticket: ", globalTicket, " Apertura: ", globalPositionOpen, " Profit: ", globalGross, " Precio: ", globalPrice, " Trail: ", globalPositionTrailing, " Stop: ", globalPositionStop);
     }
   else
     {
      resetInit();
     }
  }

//+------------------------------------------------------------------+
//| PRICE CONVERT                                                    |
//+------------------------------------------------------------------+
long priceConvert(double price)
  {
   string price_str = DoubleToString(price, 5);
   string parts[];
   int count = StringSplit(price_str, '.', parts);
   if(StringLen(parts[1])==4)
     {
      parts[1] = parts[1] + "0";
     }
   long price_int = StringToInteger(parts[0] + parts[1]);
   return price_int;
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| RESET INIT                                                       |
//+------------------------------------------------------------------+
void resetInit()
  {
   globalPositionInit = true;
   globalPositionTrailing = 0;
   globalTickValue = 0;
   globalTicket = 0;
   globalSymbol = "";
   globalPositionSymbol = "";
   globalPositionType = 0;
   globalPositionOpen = 0;
   globalPositionStop = 0;
   globalGross = 0;
   globalPrice = 0;
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| UPDATE STOPLOSS                                                  |
//+------------------------------------------------------------------+
void setStopLoss()
  {
   double priceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
   double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double newStopLoss = priceOpen - globalStopLoss * tickSize;
   trade.OrderModify(globalTicket, 0, priceOpen, newStopLoss, 0, CLR_NONE);
  }
//+------------------------------------------------------------------+
Comentarios  Leer Más

Cómo instalar tienda de windows Microsoft Store

Código paso a paso para instalar la tienda de windows “Microsoft Store”.

En mi canal de youtube hay un video del paso a paso:

  1. Abrir Power Shell.

  2. Ejecutar codigo

    Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
    
Comentarios  Leer Más

Cómo crear página web en Github Pages

Código paso a paso para crear una pagina web usando el hosting gratuito de Github Pages, con dominio personalizado y certificado SSL.

En mi canal de youtube hay un video del paso a paso:

  1. Buscar pantilla HTML
    • Descargar
    • Descomprimir
  2. Crear Repositorio
    • Agregar al nombre del repositorio = .github.io
    • Vincular repositorio
    • Subir plantilla
  3. Configurar dominio
    • Crear DNS personalizados
      185.199.108.153
      185.199.109.153
      185.199.110.153
      185.199.111.153
      
    • Crear C-NAME
    • Esperar creación de SSL
Comentarios  Leer Más

Cómo hacer deploy App Net Core en AWS

Código paso a paso para desplegar un proyecto API Net Core en AWS Elastic Beanstalk.

En mi canal de youtube hay un video del paso a paso:

  1. Crear Aplicación Elastic Beanstalk
    • Application Name / Enviroment / Domain / Platform Linux
    • Create Service Role
    • Create EC2 Intance Profile / IAM
    • Create Role / AWS Service / UseCase = EC2
    • Add Policies = WebTier / WorkerTier / MulticontainerDocker
    • VPC / Public IP Address = Activated / Instance Subnets
    • EC2 Security Gropus = default
  2. Configurar Visual Studio
    • Crear Usuario / Crear Grupo / Crear Role = administrator
    • Descargar e Instalar = AWS Toolkit for Visual Studio
    • Crear perfil / Access Key / Secret Key
Comentarios  Leer Más

Cómo hacer deploy de react.js en AWS

Código paso a paso para desplegar un proyecto React.JS en AWS Elastic Beanstalk.

En mi canal de youtube hay un video del paso a paso:

  1. Crear S3
    • Block all public access
    • Properties / Static website hosting / index.html
    • Bucket policy / S3 / GetObject
    • “Principal”: “*”
  2. Crear proyecto Reat.JS
    • npx create-react-app reactapp
    • npm run build
  3. Hacer deploy
    • login en aws
    • https://aws.amazon.com/es/cli/
    • aws –version
    • aws configure
      AWS Access Key ID [None]: AKIAURUY3VAMM35KPIJA
      AWS Secret Access Key [None]: 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
      Default region name [None]: us-west-2
      Default output format [None]: json
      
    • aws s3 sync build/ s3://reactapp-bucket
Comentarios  Leer Más