Получайте новости с этого сайта на
domo

Pivot (поддержка и сопротивление) выводим на график значения

PORTFOLIO_EX pivot_sberp;
DESCRIPTION pivot_sberp;
CLIENTS_LIST  ALL_CLIENTS;
FIRMS_LIST ALL_FIRMS;

PROGRAM

' Настраиваемые параметры
ClassCodeList="EQBR" ' код класса инструмента
Instrument="SBERP03" ' название инструмента
Interval_day=-1' интервал (таймфрейм) на графике
Interval=30
DayToFind=30 ' сколько дней назад искать свечи (можно уменьшить, чтоы ускорить работу программы)
CandleToFind=2 ' сколько свечей надо найти

DELETE_ALL_ITEMS()
DELETE_ALL_LABELS ("sberp_day")

CandleCount=0
CurYear=get_value(GET_DATETIME(), "YEAR")
CurMonth=get_value(GET_DATETIME(), "MONTH")
CurDay=get_value(GET_DATETIME(), "DAY")
CurHour = GET_VALUE(GET_DATETIME(), "Hour")
CurMin = GET_VALUE(GET_DATETIME(), "Min")
CurMin = Interval*Floor(CurMin/Interval) ' округляем минуты до "интервальных"
for i from 1 to DayToFind
  TextData=fTextData(CurYear,CurMonth,CurDay) &""
  TextTime=fTextTime(CurHour,CurMin) & ""
  if (CandleCount<CandleToFind) ' если нашли сколько нам надо свечей - гоняем пустой цикл
    Candle=GET_CANDLE(ClassCodeList,Instrument, "", Interval_day & "", "PRICE", TextData, "")
    Open=GET_VALUE (Candle, "Open")+0
    if (Open>0)  
      CandleCount=CandleCount+1
      if (CandleCount>1)
      H=GET_VALUE (Candle, "High")+0
      L=GET_VALUE (Candle, "Low")+0
      C=GET_VALUE (Candle, "Close")+0
      output=CREATE_MAP()
      output=SET_VALUE(output,"Date",TextData)
      output=SET_VALUE(output,"Time",TextTime)
      output=SET_VALUE(output,"Open",Open)
      output=SET_VALUE(output,"High",H)
      output=SET_VALUE(output,"Low",L)
      output=SET_VALUE(output,"Close",C)
P = (H + L + C) / 3
R1 = 0+apply_scale(((2*P) - L),4)
R2 = 0+apply_scale ((P + H - L),4)
R3 = 0+apply_scale((H + 2*(P - L)),4)
S1 = 0+apply_scale(((2*P) - H),4)
S2 = 0+apply_scale((P - H + L),4)
S3 = 0+apply_scale((L - 2*(H - P)),4)
label_params=create_map()
label_params=set_value(label_params,"TEXT", "R3 = "&R3)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 70)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Сопротивление 3")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "R2 = "&R2)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 71)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Сопротивление 2")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "R1 = "&R1)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 72)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Сопротивление 1")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "Pivot = "&P)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 73)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Pivot")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "S1 = "&S1)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 74)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Поддержка 1")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "S2 = "&S2)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 75)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Поддержка 2")
id=ADD_LABEL("sberp_day", label_params)

label_params=create_map()
label_params=set_value(label_params,"TEXT", "S3 = "&S3)
'label_params=set_value(label_params,"IMAGE_PATH", "image.bmp")
label_params=set_value(label_params,"ALIGNMENT", "RIGHT")
label_params=set_value(label_params,"YVALUE", 76)
label_params=set_value(label_params,"DATE", 20110525)
label_params=set_value(label_params,"TIME", "")
label_params=set_value(label_params,"R", 255)
label_params=set_value(label_params,"G", 255)
label_params=set_value(label_params,"B", 255)
label_params=set_value(label_params,"TRANSPARENCY", 0)
label_params=set_value(label_params,"FONT_FACE_NAME", "MS Sans Serif")
label_params=set_value(label_params,"FONT_HEIGHT", 8)
label_params=set_value(label_params,"HINT", "Поддержка 3")
id=ADD_LABEL("sberp_day", label_params)

      ADD_ITEM(CandleCount,output)
      WRITELN(OutFile, TextData  & "," & TextTime & "," & Open & "," & H & "," & L & "," & C)
      end if
'      Return
    end if
    ' откат на "интервал" назад
    
        CurDay=CurDay-1
        if curDay<1
          CurDay=31
          CurMonth=CurMonth-1
          if CurMonth<1
            CurMonth=12
            CurYear=CurYear-1
            if CurYear<0
              message ("Не найдены котировки до рождества Христова! <img src="http://www.trade-bot.ru/wp-includes/images/smilies/icon_biggrin.gif" alt=":-D" class="wp-smiley"> ",1)
                    end if
      end if
    end if
  end if
end for

' функция перевода даты в текстовый формат
func fTextData(Year,Month,Day)
  if (LEN(Month) < 2)
    Month = "0" & Month
  end if
    if (LEN(Day) < 2)
    Day = "0" & Day
  end if
  result = Year & Month & Day
end func

' функция перевода времени в текстовый формат
func fTextTime(Hour,Min,Sec)
  if (LEN(Hour) < 2)
    Hour = "0" & Hour
  end if
    if (LEN(Min) < 2)
    Min = "0" & Min
  end if
  result = Hour & Min & "00"
end func

END_PROGRAM

PARAMETER Date;
PARAMETER_TITLE Дата;
PARAMETER_DESCRIPTION Дата;
PARAMETER_TYPE STRING(30);
END

PARAMETER Time;
PARAMETER_TITLE Время;
PARAMETER_DESCRIPTION Время;
PARAMETER_TYPE STRING(30);
END

PARAMETER Open;
PARAMETER_TITLE Open;
PARAMETER_DESCRIPTION Open;
PARAMETER_TYPE NUMERIC(10,4);
END

PARAMETER High;
PARAMETER_TITLE High;
PARAMETER_DESCRIPTION High;
PARAMETER_TYPE NUMERIC(10,4);
END

PARAMETER Low;
PARAMETER_TITLE Low;
PARAMETER_DESCRIPTION Low;
PARAMETER_TYPE NUMERIC(10,4);
END

PARAMETER Close;
PARAMETER_TITLE Close;
PARAMETER_DESCRIPTION Close;
PARAMETER_TYPE NUMERIC(10,4);
END

END_PORTFOLIO_EX

Добро пожаловать! Вы первый раз здесь?

Что вы ищете? Выберите интересующие вас темы, чтобы улучшить свой первый опыт:

Применить и продолжить