#property script_show_inputs
#include <Trade\Trade.mqh>
input string Symbol = "CL-OIL"; // 거래 종목
input double TakeProfit = 50.0; // 이익실현 목표
CTrade Trade;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
// Trade 객체 초기화
Trade.SetExpertMagicNumber(123456); // 매직 넘버 설정 (원하는 숫자로 변경 가능)
while(!IsStopped())
{
// 현재 열린 포지션 확인
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
if(PositionSelectByTicket(PositionGetTicket(i)))
{
// 현재 포지션이 이익실현 목표에 도달했는지 확인
if(PositionGetDouble(POSITION_PROFIT) >= TakeProfit)
{
ulong ticket = PositionGetTicket(i);
double volume = PositionGetDouble(POSITION_VOLUME);
long positionType = PositionGetInteger(POSITION_TYPE);
// 포지션 종료
if(!Trade.PositionClose(ticket))
{
Print("포지션 종료 실패: ", GetLastError());
continue;
}
// 새로운 포지션 열기
ENUM_ORDER_TYPE orderType = (positionType == POSITION_TYPE_BUY) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL;
if(!Trade.PositionOpen(Symbol, orderType, volume, 0, 0, 0))
{
Print("새 포지션 열기 실패: ", GetLastError());
}
}
}
}
Sleep(1000); // 1초 대기
}
}
수익실현중인 포지션을 청산 후 재진입하는 로직입니다.
'잡쓸식' 카테고리의 다른 글
pce지수가 주식에 미치는 영향 (1) | 2025.03.28 |
---|---|
주식 양도세금 줄이기 (0) | 2025.02.06 |
2025년 주식 관련 세금 변경 내용 (0) | 2025.02.06 |
8월20일 상승예상 (0) | 2024.08.20 |
24년 8월 19일 상승 예상 종목 (0) | 2024.08.16 |